setting multiple jar files as classpath in cygwin

[亡魂溺海] 提交于 2019-12-13 12:32:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!