简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM