问题
I have the program x.java in c:\cygwin\programs\x.java and it uses y.jar and z.jar that are also in the folder c:\cygwin\programs.
In windows:
c:cygwin\programs>javac -classpath c:\cygwin\programs\y.jar;c:\cygwin\programs\z.jar x.java
No errors.
In cygwin
(1)
$javac -classpath c\:/cygwin/programs/y.jar;c\:/cygwin/programs/z.jar x.java
Errors: $'PK\003\004': Command not found.
(2)
$javac -classpath c:\cygwin\programs\y.jar;c:\cygwin\programs\z.jar x.java
Errors: -bash command Command not found.
(3)
$javac -classpath 'c:/cygwin/programs/y.jar;c:/cygwin/programs/z.jar' x.java
No error.
Why is it giving error in case of (1),(2)...
回答1:
You are messing up with escape character back-slash \. In Unix based environment, it's better to use / as path separator. If you want to use backlashes for some reason, use an additonal backslash i.e. \\ to treat it as literal in the path.
Because of above, first tow statements are not resulting into correct path and hence failure.
回答2:
Cygwin treats the ; character as starting a new command line, so in (1) it is trying to execute the separate commands
$ javac -classpath c\:/cygwin/programs/y.jar
$ c\:/cygwin/programs/z.jar x.java
The error message is from Cygwin trying to execute the jar file directly as a script.
You can quote the entire argument with '' as in (3), or escape the semicolon:
$ javac -classpath c\:/cygwin/programs/y.jar\;c\:/cygwin/programs/z.jar x.java
来源:https://stackoverflow.com/questions/13389701/setting-multiple-jar-files-as-classpath-in-cygwin