Reputation: 41
I have a problem deploying an application with SWT components.
I read SO link and incorporated SWT with swing into my code.
When I run it in eclipse 3.7.1 Indigo (Ctrl+F11 or Alt + Shift X, J).
It runs perfectly inside eclipse.
However when I export the file as a "runnable JAR":
The application itself runs fine, but the SWT file choosers don't.
When I export the file as a JAR, i.e. adding the manifest according to: wiki eclipse link + SO link + SO link + SO link and I get the error listed in the troubleshoot section (eclipse wiki). I checked all the solutions listed there but they didn't work for me.
Questions:
swt.jar
is correctly named and in the runtime folder and the main class is correct,but it still gives the error?:Could not find the main class. Program will exit.
I am assuming the simplest solution would be to just use Swing file choosers. But I wanted to know how to get SWT applications to run outside eclipse.
Regards
UPDATE: Turns out that all the .jar
files (in the library build path) need to be added to the manifest. I was just adding the swt.jar
which is why I was getting the Could not find main class...
error. Adding the other .jar
to the manifest solved Q3 above.
When running from command line: SWT components work fine when exporting both jar + runnable jars.
However, the SWT components don't work when trying to run the runnable jar by double clicking. Q1 and Q2 still unsolved (SWT file choosers don't work when double clicking but work in cmd java -jar
...).
Upvotes: 3
Views: 2195
Reputation: 41
Solved Q1, Q2 by java can run jar from cmd but not by double clicking.
Funnily enough, updating to jre 7u1 also solved my problem. Downloaded from http://www.oracle.com/technetwork/java/javase/downloads/jre-7u1-download-513652.html.
Q3 Manifest:
Manifest-Version: 1.0
Class-Path: swt.jar example.jar(add other .jar files after a space, I had forgotten the other jar)
Main-Class: mypackage.MyClassWithMainMethod
(blank line at end of file)
Thanks for the help
Further Clarity: You can manually create a manifest when exporting as a "jar". Dont need to do it manually, when exporting as "runnable jar".
Upvotes: 1