javac 类路径选项在当前目录中有多个 jar 文件导致错误 [英] javac classpath option with multiple jar files in current directory causing error
问题描述
环境:Windows 7、Java 6.
Environment: Windows 7, Java 6.
尝试使用 -cp 选项编译 .java 文件.该文件使用当前目录中的单个 jar 文件以及当前目录中的其他一些 jar 文件.
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.
javac -cp ./*.jar MyFile.java
不起作用.
javac -cp ./* MyFile.java
不起作用
javac -cp ./MyJar.jar MyFile.java
作品
前两种情况,我收到无效标志错误.有人可以解释这种行为吗?
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.
推荐答案
评论中提供的两个链接的引用来源以及This question may have a answer here:"中,不完全解释观察到的行为.
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
应该有效.显然在 Windows 中使用双引号和/或分号.作品:
Should have worked. Apparently using double quotes and/or a semi-colon in windows. works:
javac -cp "./*";我的文件.java
javac -cp "./*" MyFile.java
javac -cp ./*;我的文件.java
javac -cp ./*; MyFile.java
javac -cp "./*;";我的文件.java
javac -cp "./*;" MyFile.java
javac -cp *;我的文件.java
javac -cp *; MyFile.java
javac -cp "*";我的文件.java
javac -cp "*" MyFile.java
javac -cp "*;";我的文件.java
javac -cp "*;" MyFile.java
文档中没有提到这一重要事实.
Nowhere in the documention is this important fact mentioned afaik.
所以我想在 WINDOWS 7 64 位上,使用 java 1.6.0_75 使用双引号或在使用通配符时始终使用分号 *
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 *
这篇关于javac 类路径选项在当前目录中有多个 jar 文件导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!