如何从 Cygwin 运行 Java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9690756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run Java from Cygwin
提问by blaughli
I'm trying to write a BASH script to get my Java program to run(common issue, right?). I just can't quite get it to work. After many edits, here's how I am trying to set the classpath and then execute the program:
我正在尝试编写一个 BASH 脚本来运行我的 Java 程序(常见问题,对吧?)。我只是不能让它工作。经过多次编辑,这是我尝试设置类路径然后执行程序的方法:
java -classpath 'cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0.jar:/cygdrive
/c/Projects/common/lib/jdom-1.0.jar:/cygdrive/c/Projects/common/lib/jsoup-1.6.1.jar:
/cygdrive/c/Projects/common/lib/mysql-connector-java-5.1.18-bin.jar:/cygdrive/c/Projects
/Freereader/bin/"' com.free.syndication.SQLfeeder
Sorry the the jumble, I'm just trying to do everything at once. It tells me that the main class of my program cannot be found!((
对不起,混乱,我只是想一次做所有的事情。它告诉我找不到我的程序的主类!((
Any ideas?
有任何想法吗?
采纳答案by rrhartjr
- Java classpath uses semicolon as the token separator.
- Use backticks instead of single quotes
- Java 类路径使用分号作为标记分隔符。
- 使用反引号代替单引号
Try:
尝试:
java -classpath `cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0.jar;/cygdrive
/c/Projects/common/lib/jdom-1.0.jar;/cygdrive/c/Projects/common/lib/jsoup-1.6.1.jar;
/cygdrive/c/Projects/common/lib/mysql-connector-java-5.1.18-bin.jar;/cygdrive/c/Projects
/Freereader/bin/"` com.free.syndication.SQLfeeder
回答by adarshr
Don't you need backticks?
你不需要反引号吗?
java -classpath `cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0.jar:/cygdrive
/c/Projects/common/lib/jdom-1.0.jar:/cygdrive/c/Projects/common/lib/jsoup-1.6.1.jar:
/cygdrive/c/Projects/common/lib/mysql-connector-java-5.1.18-bin.jar:/cygdrive/c/Projects
/Freereader/bin/"` com.free.syndication.SQLfeeder
回答by Andrey Starodubtsev
- You must use backticks ( '`' symbol ) or $(cmd) bash sytax to substitute cmd output
- java do not understand unix- (cygwin-) style paths, only windows-style.
- 您必须使用反引号( '`' 符号)或 $(cmd) bash 语法来替换 cmd 输出
- java 不了解 unix- (cygwin-) 样式路径,只了解 windows 样式。
And at last first link in googleanswers you question
最后谷歌中的第一个链接回答了你的问题
回答by user1010997
- In bash, the syntax
$(command)
is clearer than the backticks`command`
cygpath
has a-p
option to convert PATH-like values (as opposed to single path names) between Windows and Unix, i.e.cygpath -pu 'C:\Users\me\bin;C:\Users\me\project\bin'
will give/cygdrive/c/Users/me/bin:/cygdrive/c/Users/me/project/bin
cygpath -pw
will do the same in the opposite direction
- 在 bash 中,语法
$(command)
比反引号更清晰`command`
cygpath
可以-p
选择在 Windows 和 Unix 之间转换类似 PATH 的值(而不是单个路径名),即cygpath -pu 'C:\Users\me\bin;C:\Users\me\project\bin'
会给/cygdrive/c/Users/me/bin:/cygdrive/c/Users/me/project/bin
cygpath -pw
将在相反的方向做同样的事情
Note that cygpath -u "/cygdrive/c"
(as in your question) will not change anything, since the directory name is already in the desired (Unix) syntax. You could omit it just as well.
请注意cygpath -u "/cygdrive/c"
(如您的问题)不会改变任何内容,因为目录名称已经在所需的(Unix)语法中。你也可以省略它。
So, the command becomes:
因此,命令变为:
CP="C:/Projects/common/lib/rome-1.0.jar;C:/Projects/common/lib/jdom-1.0.jar;C:/Projects/common/lib/jsoup-1.6.1.jar;
C:/Projects/common/lib/mysql-connector-java-5.1.18-bin.jar;C:/Projects
/Freereader/bin"
# for a Windows Java binary:
java -classpath "$(cygpath -pw "$CP")" com.free.syndication.SQLfeeder
# for a Unix Java binary:
java -classpath "$(cygpath -pu "$CP")" com.free.syndication.SQLfeeder
Alternatively, you can start with a Unix-style class path, but the commands stay the same. In either case, you can of course omit the call to cygpath if the class path is already in the desired syntax.
或者,您可以从 Unix 样式的类路径开始,但命令保持不变。在任何一种情况下,如果类路径已经在所需的语法中,您当然可以省略对 cygpath 的调用。
回答by typelogic
The main cause of the issue is NOT the backtic but instead the issue of colon versus semi-colon. Since in cygwin, the java running there is for DOS/Windows environment it is expecting ';' as the path separator.
问题的主要原因不是反引号,而是冒号与分号的问题。因为在 cygwin 中,在那里运行的 java 是针对 DOS/Windows 环境的,它期望';' 作为路径分隔符。
While backtic does help, the main root cause of the issue must be emphasize the difference between ':' and ';' when Java is in Unix or in Windows environment.
虽然 backtic 确实有帮助,但问题的主要原因必须是强调 ':' 和 ';' 之间的区别。当 Java 在 Unix 或 Windows 环境中时。