I'm trying to run a java program from a jar file. Java can't find a supporting marc4j class. What am I doing wrong. Here are the details
Within my current directly is MarcTry.jar
which has my main class. There is also marc4j.jar which has the missing class:
org/marc4j/MarcReader
For example:
java -jar MarcTry.jar Exception in thread "main" java.lang.NoClassDefFoundError: org/marc4j/MarcReader Caused by: java.lang.ClassNotFoundException: org.marc4j.MarcReader 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) Could not find the main class: marctry.Main. Program will exit.
I've tried
java -jar MarcTry.jar -classpath marc4j.jar
with and without the marc4j.jar a fully qualified path.
Any ideas are welcome.
The classpath is ignored when you are using the "-jar" switch. Specify both jars with "-classpath" and execute the main class with the fully qualified name.
E.g. java -cp MarcTry.jar;marc4j.jar com.domain.MainClass
.. or add marc4j.jar to the classpath entry in the manifest file of MarcTry.jar
You can read about adding jars to the classpath of the manifest file here:Adding Classes to the JAR File's Classpath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With