java javac 类路径选项在当前目录中有多个 jar 文件导致错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25025018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javac classpath option with multiple jar files in current directory causing error
提问by Brian
Environment: Windows 7, Java 6.
环境:Windows 7、Java 6。
Trying to compile a .java file with -cp option. The file uses a single jar file that's in the current directory ALONG WITH some other jar files in the current directory.
尝试使用 -cp 选项编译 .java 文件。该文件使用当前目录中的单个 jar 文件以及当前目录中的其他一些 jar 文件。
javac -cp ./*.jar MyFile.java
doesn't work.
不起作用。
javac -cp ./* MyFile.java
doesn't work
不起作用
javac -cp ./MyJar.jar MyFile.java
works
作品
First two cases, I get a invalid flag error. Can someone explain this behavior?
前两种情况,我收到无效标志错误。有人可以解释这种行为吗?
And I checked if it is spaces issue, there are no spaces anywhere in my full file paths.
我检查了它是否是空格问题,我的完整文件路径中的任何地方都没有空格。
回答by Brian
The quoted sources for the two links provided in the comments as well as in the "This question may already have an answer here:", do not completely explain the observed behavior.
评论中提供的两个链接的引用来源以及“这个问题在这里可能已经有了答案:”,并不能完全解释观察到的行为。
javac -cp ./*.jar MyFile.java
javac -cp ./*.jar MyFile.java
Won't work, because the wildcard * usage in this context differs from normal usage. This can be understood from the documentation. * always represents full file(s) and not partial file names.
行不通,因为此上下文中的通配符 * 用法与正常用法不同。这可以从文档中理解。* 始终代表完整文件而不是部分文件名。
javac -cp ./* MyFile.java
javac -cp ./* MyFile.java
Should have worked. Apparently using double quotes and/or a semi-colon in windows. works:
应该工作。显然在 Windows 中使用双引号和/或分号。作品:
javac -cp "./*" MyFile.java
javac -cp ./*; MyFile.java
javac -cp "./*;" MyFile.java
javac -cp *; MyFile.java
javac -cp "*" MyFile.java
javac -cp "*;" MyFile.java
javac -cp "./*" MyFile.java
javac -cp ./*; 我的文件
javac -cp "./*;" 我的文件
javac -cp *; 我的文件
javac -cp "*" MyFile.java
javac -cp "*;" 我的文件
Nowhere in the documention is this important fact mentioned afaik.
文档中没有任何地方提到这一重要事实 afaik。
So I guess ON WINDOWS 7 64 bit, with java 1.6.0_75 EITHER USE DOUBLE QUOTES OR ALWAYS A SEMI-COLON WHEN USING WILDCARD *
所以我猜在 WINDOWS 7 64 位上,使用 java 1.6.0_75 使用双引号或始终使用通配符时使用分号 *
回答by Kalpesh Soni
use backslash in windows?
在 Windows 中使用反斜杠?
try
尝试
javac -cp .\* MyFile.java
javac -cp .\* MyFile.java
also note Broken wildcard expansion for Java7 commandline on Windows(7?)