I have a lib directory with a thousand jars, where main.jar contains the main method, and the class that contains the main method is org.test.Main.
The directory structure is as follows:
# tree
.
└── lib
├── a.jar
├── b.jar
├── c.jar
└── main.jar
and now I use these commands to run the message class not found error
# class not found
java -cp lib org.test.Main
# class not found
java -cp lib/*.jar org.test.Main
# class not found
java -cp lib/* org.test.Main
# class not found,
export CLASSPATH=/mydir/lib
java org.test.Main
unset CLASSPATH
and the follow commands work fine, It seems that the jar in which the main class resides must be specified separately in the classpath
# work fine
java -cp lib/*:lib/main.jar org.test.Main
# work fine, the order is not the question
java -cp lib/main.jar:lib/* org.test.Main
# work fine, list every jar
java -cp lib/main.jar:lib/a.jar::lib/b.jar:lib/c.jar org.test.Main
it looks weird. is there any java specification introduce how the classpath work?
I’m confused about how the java classpath works, and i wonder how it works.
user25075193 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.