[java] Eclipse, SWT, Jar files

Started by
9 comments, last by ippo 19 years, 8 months ago
I recently wrote a small application for my brother, I used the Eclipse IDE and for the GUI i used SWT. I have several problems i just can't really fix. 1. I cannot get a exec jar file to work (i am thrown errors)...Most likely I am not setting it up right, within eclipse itself the app works perfectly. I was wondering how I can make an exec jar file for my brother to run. 2. I am pretty sure that even if i get the exec jar file to run on my system..due to him not having eclipse installed (ie. no swt library) he will not be able to run this application. How would I go about handling this? Thx for any help. ippo. ps. If you don't feel like explaining this but do know of a good resource to read..feel free to just post a link. In my searches I am coming up with nothing (or perhaps i just don't know what i'm looking for)
cause even if my legs are chopped off, aslong as I have a thumb I''ll catch a ride.
Advertisement
Hi,

There are several things to consider when using a JAR file.

1. Dependencies. When you have simple .class files, you can have dependencies, like SWT, in another JAR file, as long as you have that filein your CLASSPATH. I *think* you can't have the JAR file in your main JAR file - it wouldn't work - at least I haven't been able to get it to work. So, you would have to extract all dependencies and compress them as simple .class file with your own app into the JAR. So, in your case, you'd have to get all the SWT files out of their own JAR, and into yours - being careful to preserve the package structure, of course.

2. Program resources. If you are using stuff like images, or text files, and such in your program, then you have to load them through the Class.getResource method (or one of it's siblings, like System.getSystemResource, I think). The java.io.File will *not* work inside a JAR.

3. ... Ehhh, there was something else I was gonna say... :)


Ohhh, yeah.

3. Manifest file. You gotta tell the JAR file which class you want to run. So, inside you have to have the file META-INF/MANIFEST.MF, inside which you have to have a line which reads something like this:

Main-Class: fully.qualified.ClassName


[smile]

Hope that helps.

Vovan
Vovan
bleh, i still can't get it...

i get the "Illegal thread exception" error..which probably has to do with the usage of swt... I pointed the classpath to swt, but no luck. Oh well..


thx for the help tho ;)

ippo.

/me breaks out the c++
cause even if my legs are chopped off, aslong as I have a thumb I''ll catch a ride.
Hi,

Pfft, don't give up so easy there. [smile] Figured stuff like this out is where the fun's at. ;)

Also, I never heard of an illegal thread exception... (Granted, I never used SWT...) If you post the actual name of the exception it spits out and the message, maybe that would help us help you. [grin]

Vovan
Vovan
Image Hosted by ImageShack.us

Sorry, it was "fatal" not "illegal". It is most likely because SWT is not setup to run right. Also, if i run it from the command line..it tells me the main class isn't found..which i think is bs because my manifest file points right to it :/ I guess now that I already ported what i was doing to c++ and sent it off will give me more time to fix this problem so it won't happen in the future..

[Edited by - ippo on August 5, 2004 1:24:44 PM]
cause even if my legs are chopped off, aslong as I have a thumb I''ll catch a ride.
Quote:Original post by ippo
Image Hosted by ImageShack.us

Sorry, it was "fatal" not "illegal". It is most likely because SWT is not setup to run right. Also, if i run it from the command line..it tells me the main class isn't found..which i think is bs because my manifest file points right to it :/ I guess now that I already ported what i was doing to c++ and sent it off will give me more time to fix this problem so it won't happen in the future..
yeah, you don't have the manifest setup properly, it's nothing wrong with your code.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

^

that's exactly what i have been doing...

the only thing differnce i have is the main class is part of a package so it comes out being like "launcher.Launcher" for the Main class, that really shouldn't be a problem though..should it?
cause even if my legs are chopped off, aslong as I have a thumb I''ll catch a ride.
No it shouldn't. Can you post your manifest file so that we can have alook at it and determine if there is anything wrong with it.
garazdawi - 'I put the laughter back in slaughter'
Hi,

And also make sure that the manifest file is in the correct directory inside the JAR. [smile]

+ app.jar  |  +- META-INF  | |  | +- MANIFEST.MF  |  +- launcher  | |  | +- Launcher.class  | +- AnotherLauncher.class  |  +- otherpackage  +- ...


[smile]

Vovan

EDIT: Oh, I guess you are generating the JAR automatically... So it should be put where it belongs...
Vovan
Manifest-Version: 1.0Sealed: trueMain-Class: gui.Launcher


is the contents of my file...

and ^, that is how my project looks..almost exactly ;d (gg test/example name usage ;d)
cause even if my legs are chopped off, aslong as I have a thumb I''ll catch a ride.

This topic is closed to new replies.

Advertisement