简体   繁体   English

在Java命令行上指定多个-cp或-classpath条目

[英]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). Java文档非常明确地说明了如何定义多个类路径目录(由;或:分隔,取决于OS)。

However, I have a situation where a framework is already setting the -cp flag to an application directory. 但是,我遇到一种情况,即框架已经将-cp标志设置为应用程序目录。 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. 我能够在命令行中添加其他选项,因此我想知道为什么我不能添加自己的附加-cp选项来指定我的路径。

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. 实验表明,如果多次指定-cp或-classpath,则Java CLI不会抱怨。

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 将导致仅“ lib2”类在类路径上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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