samack samack - 9 months ago 64
Java Question

Compilation error with external Jar

I am trying to command line compile my code and I cannot get it to run properly. My project was in eclipse and I could specify the location of a jar file to include but the command line is another issue. All .java and the .jar file are in the same director.

I can compile with

javac -classpath opencsv-2.3.jar *.java

I get the following exception if I try to run my code.

java ClassificationGenerator

Exception in thread "main" java.lang.NoClassDefFoundError: au/com/bytecode/opencsv/CSVReader

I tried running the code with

java -classpath opencsv-2.3.jar ClassificationGenerator

but then I get

Exception in thread "main" java.lang.NoClassDefFoundError: ClassificationGenerator
Caused by: java.lang.ClassNotFoundException: ClassificationGenerator
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(

Answer Source

You need to give the jar in the classpath while running, aw well:

java -classpath .;opencsv-2.3.jar ClassificationGenerator