在 Linux 中的类路径上使用 javac 和多个特定的 jar(波浪号在冒号后不扩展)
我正在尝试通过类似于以下的命令编译一个使用两个 jar 文件(trove 和 apache commons 集合)的 java 源文件
javac -cp ~/.m2/repository/gnu/trove/trove/3.0.0/trove-3.0.0.jar:~/git-workspace/grid/libs/commons-collections-3.2.1.jar $(find . -name TimeJavaCode.java)
在上面的情况下,commons 代码未成功包含,并且出现编译错误使用公共库。如果我颠倒导入的顺序,那么我在使用 trove 时会出现编译错误。我尝试导出到变量以及单引号和双引号 cp 字符串,但均无济于事(在这种情况下,所有导出都不会成功,并且 trove 和 commons 都会出现编译错误)。
我已经看过以下之前的问题:
Setting multiple jars in java classpath
包含两个的正确方法是什么罐子?
I'm trying to compile a java source file that uses two jar files (trove and apache commons collections) via commands similar to the following
javac -cp ~/.m2/repository/gnu/trove/trove/3.0.0/trove-3.0.0.jar:~/git-workspace/grid/libs/commons-collections-3.2.1.jar $(find . -name TimeJavaCode.java)
In the above case, the commons code is not successfully included and there is a compile error where I'm using the commons library. If I reverse the order of the imports, then there are compile errors where I'm using trove. I've tried exporting to a variable as well as single and double quoting the cp string to no avail (in such cases none of the exports succeed, and there are compile errors for both trove and commons).
I've already looked at the following previous questions:
Setting multiple jars in java classpath
Using multiple .jar with javac
What is the correct way to include two jars?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用
~
,而是更改为真实路径(即/home//...
),它应该按预期工作。为了澄清这一点,这不是 Java 特有的问题,请在 shell 中尝试以下操作:
您应该得到类似以下内容:(
其中
icyrock.com
当然会替换为您的登录名)。第二个 ~ 不是由 bash 扩展的,这就是为什么会遇到问题。你期望它扩展到:这就是为什么你有“第一个有效,第二个无效”的经历。
查看 bash 手册:
你可以看到这个:
(强调我的),因此只有第一个波浪号被扩展,因为第二个波浪号不在单词的开头。
Instead of using
~
, change to the real path (i.e./home/<your username>/...
), it should work as expected.To clarify, this is not a Java-specific problem, try this in your shell:
You should get something like:
(where
icyrock.com
is, of course, replaced by your login). The second ~ is not expanded by bash, which is why run into problems. You are expecting it to expand to:This is why you have the "first works, second doesn't" experience.
Looking at the bash manual:
you can see this:
(emphasis mine), so only first tilde is expanded, as the second tilde is not at the beginning of the word.