Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying multiple -cp or -classpath entries on java command line

Tags:

java

classpath

The Java documentation is fairly explicit in how to define multiple classpath directories (delimited by ; or : depending on OS).

However, I have a situation where a framework is already setting the -cp flag to an application directory. I have the ability to add additional options to the command line, so I was wondering why I can't add my own additional -cp option that specifies my path.

Will this automatically combine the classpath entries, or will it result in only one of the two entries being used? If the latter, which one will be used?

like image 590
Pickles Avatar asked Dec 23 '22 15:12

Pickles


1 Answers

Experiment has shown that the Java CLI doesn't complain if you specify -cp or -classpath multiple times.

However, the result is that whatever classpath was set last will override any previous arguments. Thus:

java -cp lib1/* -cp lib2/* MyProgram

will result in only the "lib2" classes being on the classpath

like image 138
Pickles Avatar answered Mar 23 '23 00:03

Pickles