简体   繁体   English

在cygwin中将多个jar文件设置为类路径

[英]setting multiple jar files as classpath in cygwin

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 .我有计划x.javac:\\cygwin\\programs\\x.java ,它使用y.jarz.jar ,同时也是在文件夹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在 cygwin 中

(1) (1)

$javac -classpath c\:/cygwin/programs/y.jar;c\:/cygwin/programs/z.jar x.java 

Errors: $'PK\003\004': Command not found.

(2) (2)

$javac -classpath c:\cygwin\programs\y.jar;c:\cygwin\programs\z.jar x.java 

Errors: -bash command Command not found.

(3) (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),(2)的情况下会出错......

You are messing up with escape character back-slash \\ .您正在搞乱转义字符反斜杠\\ In Unix based environment, it's better to use / as path separator.在基于 Unix 的环境中,最好使用/作为路径分隔符。 If you want to use backlashes for some reason, use an additonal backslash ie \\\\ to treat it as literal in the path.如果出于某种原因要使用反斜杠,请使用附加的反斜杠,即\\\\将其视为路径中的文字。

Because of above, first tow statements are not resulting into correct path and hence failure.由于上述原因,第一条语句不会导致正确的路径,因此不会导致失败。

Cygwin treats the ; Cygwin 对待; character as starting a new command line, so in (1) it is trying to execute the separate commands字符作为开始一个新的命令行,所以在(1)中它试图执行单独的命令

$ 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.错误消息来自 Cygwin,它试图将 jar 文件直接作为脚本执行。

You can quote the entire argument with '' as in (3), or escape the semicolon:您可以像 (3) 中那样用''引用整个参数,或者转义分号:

$ javac -classpath c\:/cygwin/programs/y.jar\;c\:/cygwin/programs/z.jar x.java

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

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