I referenced one external library (Opencsv) in my project.
I added the Manifest file into the 'src' folder as:
Manifest-Version: 1.0
Main-Class: DataClean.DataPreprocess
Class-path: jars/opencsv.jar
The 'jars' is a folder contains the opencsv jar file in 'src' folder.
The complied main class is in 'DataClean' folder in 'src'.
When I create the jar, I use:
jar cfm PromoPrice_CN.jar Manifest.txt *
This command was run within 'src' folder.
Then, the JAR I created can only run within this 'src' directory. Otherwise, it gives the exceptions:
Exception in thread "main" java.lang.NoClassDefFoundError: com/opencsv/CSVReader
at DataClean.DataPreprocess.dataClean(DataPreprocess.java:154)
at DataClean.DataPreprocess.main(DataPreprocess.java:229)
Caused by: java.lang.ClassNotFoundException: com.opencsv.CSVReader
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)
... 2 more
The command I used to run the jar is:
java -jar C:\...\src\PromoPrice_CN.jar X Y Z
X, Y and Z are three input parameter for the jar.
Please help where did I do wrong?
FYI, the creation of the JAR has to be in command line for other reasons.
Thx