Reputation: 7309
I built a few Java desktop apps which all reference a common Java class library I also made. I'm having trouble running this setup outside of Netbeans. I copied all jars (the library and the programs) into some folder, but when I try to run any of the programs, they crash saying they cannot find some class from the common library.
I never tried this sort of scenario before... what am I doing wrong? I'd bet it has something to do with the classpath, and I'm looking into that. This is the error message:
D:\LAB\FIUBA\Stock84885\bin>java -jar Stock84885OrderReceiver.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: core/ILogger
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: core.ILogger
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
(ILogger is a class from the common class library).
Upvotes: 1
Views: 1282
Reputation: 36
You should include all the dependencies jars in your classpath when executing a program outside your IDE.
-cp <class search path of directories and zip/jar files>
Try this:
java -cp "lib/*" com.example.Main
Replace lib/ with the directory in which the dependencies jars are contained and com.example.Main for the class containing the main method.
Make sure that the file Stock84885OrderReceiver.jar is contained within the classpath
Upvotes: 2