Run java application from command line with external jar files

classpath, command-line, jar, java, noclassdeffounderror

Solution

If the class is in bin directory :

java -cp xxx.jar;bin pck1.pck2.MainClass

If the class is in the current directory :

java -cp xxx.jar;. pck1.pck2.MainClass

and so on...

More info in the manual, please read it at least one time... ;-)

Problem

I have an external jar file(have package structure), which contains the main class, and I can run the app from command line like this: ``` java -jar example.jar ``` But I still have another `test.class` file outside this jar file, and some classes inside this jar file will invoke the methods in `test.class`. How can I specify the `test.class` file to be used by jar file in command line? Tried many ways, always show: ``` NoClassDefFoundError for test.class ``` NB: the test.class file also use class files in example.jar file, has its own package structure. I know I can put them together in one jar file, unfortunately I need separate the test.class file.

Original source