Question

I installed WindowBuilder to Eclipse and created program that consist of one class. This class is generated directly by WinowsBuilder and only contains one empty window. I can run this program on eclipse. I exported program to jar file, but it throws error when i try to launch it. Error says that "The Java JAR "gui.jar" could not be launched." Tried to follow this tutorial http://wiki.eclipse.org/FAQ_How_do_I_create_an_executable_JAR_file_for_a_stand-alone_SWT_program%3F but it still not working.

update: when launching jar file via terminal i got following error:

  Exception in thread "main" java.lang.NoClassDefFoundError: swing2swt/layout/BorderLayout
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
at java.lang.Class.getMethod0(Class.java:2774)
at java.lang.Class.getMethod(Class.java:1663)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
  Caused by: java.lang.ClassNotFoundException: swing2swt.layout.BorderLayout
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more

How should I export SWT application as stand alone jar?

Was it helpful?

Solution

So, as a conclusion from the comments above:

  • You'll need to include all the libraries you reference in the jar export process, otherwise they won't be included in the jar file.
  • Since you're running OSX, you'll either need to use the VM argument -XstartOnFirstThread when starting your jar, or you can create a proper OSX application as described here and here
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top