1

I made simple jar for my java-application (build with SWT). In netbeans it starts normal, as it need to be. But when I'm starting it with java -jar [jarName], I have such error:

java -jar jarname.jar 
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composite
    at roxed.Main.main(Main.java:15)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Composite
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 1 more

I have downloaded SWT from http://eclipse.org/swt (linux build), unpacked jar and added this folder to the project.

Could someone to say, why I cannot execute it not from IDE?

sdf
  • 79
  • 2
  • 8

4 Answers4

2

Add swt jars in classpath. Specifically, org.eclipse.swt_x.x.x and org.eclipse.swt.win32.win32.x86_x.x.x. Where x is the version number and you will have to look for linux version and not the win32 as I have shown.

Favonius
  • 13,959
  • 3
  • 55
  • 95
1

UPDATED

The swt.jar needs to be added to the Class-Path entry in the META-INF/MANIFEST.MF file.

You can read more about Java Launcher options on this link.

CoolBeans
  • 20,654
  • 10
  • 86
  • 101
1

Found ... But not exactly. Ported project to eclipse, added all jar-s. And just exported as executable-jar. And it works...

Thanky to all anyway for participation.

sdf
  • 79
  • 2
  • 8
1

That's true java -cp libraries/swt.jar -jar jarname.jar generates the same error.

This is becouse when using -jar, Java does not use -classpath values.

You have to add libraries to Class-Path section in your manifest inside of a jar package.

For example:

Manifest-Version: 1.0
Main-Class: irisRecognition
Class-Path: ../libs/swt64.jar ../libs/bij.jar

You can find more detailed description in answer here

Community
  • 1
  • 1
berni
  • 1,955
  • 1
  • 19
  • 16