在 Linux 的类路径上使用带有多个特定 jar 的 javac(波浪号在冒号后不展开) [英] Use javac with multiple specific jars on classpath in Linux (tilde doesn't expand after colon)

查看:30
本文介绍了在 Linux 的类路径上使用带有多个特定 jar 的 javac(波浪号在冒号后不展开)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过类似于以下的命令编译一个使用两个 jar 文件(trove 和 apache commons 集合)的 java 源文件

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)

在上述情况下,commons 代码未成功包含,并且在我使用 commons 库时出现编译错误.如果我颠倒导入的顺序,那么在我使用 trove 的地方就会出现编译错误.我试过导出到一个变量以及单引号和双引号 cp 字符串都无济于事(在这种情况下,没有一个导出成功,并且 trove 和 commons 都存在编译错误).

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:

在java类路径中设置多个jar

使用多个 .jar 和 javac

包含两个 jar 的正确方法是什么?

What is the correct way to include two jars?

推荐答案

不使用~,改为真实路径(即/home//...),它应该按预期工作.

Instead of using ~, change to the real path (i.e. /home/<your username>/...), it should work as expected.

澄清一下,这不是特定于 Java 的问题,请在您的 shell 中尝试:

To clarify, this is not a Java-specific problem, try this in your shell:

$ echo ~/.bashrc:~/.bashrc

你应该得到类似的东西:

You should get something like:

/home/icyrock.com/.bashrc:~/.bashrc

(当然,icyrock.com 将替换为您的登录名).第二个 ~ 没有被 bash 扩展,这就是为什么会遇到问题.您希望它扩展到:

(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:

/home/icyrock.com/.bashrc:/home/icyrock.com/.bashrc

这就是为什么您有第一个有效,第二个无效"体验的原因.

This is why you have the "first works, second doesn't" experience.

看bash手册:

你可以看到:

如果一个词以未加引号的波浪号字符 ('~') 开头,则直到第一个未加引号的斜杠(或所有字符,如果没有未加引号的斜杠)之前的所有字符都被视为波浪号前缀.

If a word begins with an unquoted tilde character (‘~’), all of the characters up to the first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde-prefix.

(强调我的),所以只展开第一个波浪号,因为第二个波浪号不在单词的开头.

(emphasis mine), so only first tilde is expanded, as the second tilde is not at the beginning of the word.

这篇关于在 Linux 的类路径上使用带有多个特定 jar 的 javac(波浪号在冒号后不展开)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆