# [java] Eclipse, SWT, Jar files

This topic is 5066 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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)

##### Share on other sites
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

##### Share on other sites
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++

##### Share on other sites
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

##### Share on other sites

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]

##### Share on other sites
Quote:
 Original post by ippo 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.

##### Share on other sites
^

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?

##### Share on other sites
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.

##### Share on other sites
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...

##### Share on other sites
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)

• 48
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631375
• Total Posts
2999659
×