Sign in to follow this  
ippo

[java] Eclipse, SWT, Jar files

Recommended Posts

ippo    122
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 this post


Link to post
Share on other sites
vovansim    336
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 this post


Link to post
Share on other sites
ippo    122
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 this post


Link to post
Share on other sites
vovansim    336
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 this post


Link to post
Share on other sites
ippo    122
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]

Share this post


Link to post
Share on other sites
capn_midnight    1707
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.

Share this post


Link to post
Share on other sites
ippo    122
^

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 this post


Link to post
Share on other sites
vovansim    336
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 this post


Link to post
Share on other sites
ippo    122

Manifest-Version: 1.0
Sealed: true
Main-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)

Share this post


Link to post
Share on other sites
ippo    122
UPDATE:

well, i finally got it to work. For some reason my classpath wasn't being set (Even tho i WAS setting it), atleast i believe that is what was happening. In the end I just copied the swt.jar/dll all over the place until it worked. heh, quick fix, but oh well..it works.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this