简体   繁体   English

javac 类路径选项在当前目录中有多个 jar 文件导致错误

[英]javac classpath option with multiple jar files in current directory causing error

Environment: Windows 7, Java 6.环境:Windows 7、Java 6。

Trying to compile a .java file with -cp option.尝试使用 -cp 选项编译 .java 文件。 The file uses a single jar file that's in the current directory ALONG WITH some other jar files in the current directory.该文件使用当前目录中的单个 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.我检查了它是否是空格问题,我的完整文件路径中的任何地方都没有空格。

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.显然在 Windows 中使用双引号和/或分号。 works:作品:

javac -cp "./*" MyFile.java javac -cp "./*" MyFile.java

javac -cp ./*; javac -cp ./*; MyFile.java我的文件

javac -cp "./*;" javac -cp "./*;" MyFile.java我的文件

javac -cp *; javac -cp *; MyFile.java我的文件

javac -cp "*" MyFile.java javac -cp "*" MyFile.java

javac -cp "*;" javac -cp "*;" MyFile.java我的文件

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 使用双引号或始终使用通配符时使用分号 *

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?)还要注意Windows(7?) 上 Java7 命令行的损坏的通配符扩展

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

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