3

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:

  1. Why do SWT file choosers work in eclipse and not in a "runnable jar"?
  2. Why does the "runnable jar" export wizard in eclipse, not automatically incorporate SWT?
  3. Why does the export as jar not work with the manifest, when the 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...).

3
  • Where are the required libraries? What is your java.library.path?
    – trashgod
    Nov 6, 2011 at 23:08
  • In my build path (libraries), I have a swt.jar (Which I had added with Add External Jars). I also have a JRE System Library [jre6].
    – Mikail
    Nov 7, 2011 at 10:13
  • Thanks, further checking of build path libraries helped solve Q3. Class path was fixed (blogs.oracle.com/olaf/entry/jdev_including_a_classpath_in) Question updated.
    – Mikail
    Nov 7, 2011 at 13:01

1 Answer 1

1

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".

1
  • +1 for followup. This utility is handy for checking the manifest as built.
    – trashgod
    Nov 7, 2011 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.