Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

java - javac classpath option with multiple jar files in current directory causing error

Environment: 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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

Should have worked. Apparently using double quotes and/or a semi-colon in windows. works:

javac -cp "./*" MyFile.java

javac -cp ./*; MyFile.java

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

javac -cp *; MyFile.java

javac -cp "*" MyFile.java

javac -cp "*;" MyFile.java

Nowhere in the documention is this important fact mentioned 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 *


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...