在Linux中的类路径上将javac与多个特定的jar一起使用(冒号在冒号后不会扩展) [英] Use javac with multiple specific jars on classpath in Linux (tilde doesn't expand after colon)

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

问题描述

我正在尝试通过类似于以下命令的命令来编译使用两个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库时出现编译错误。如果我颠倒了导入的顺序,那么在我使用trove的地方就会出现编译错误。我尝试导出到变量以及将cp字符串单引号和双引号都无济于事(在这种情况下,导出均不会成功,并且trove和Common都有编译错误)。

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

在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

您应该d得到类似的东西:

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手册:

  • http://www.gnu.org/software/bash/manual/bashref.html#Tilde-Expansion

您可以看到以下内容:


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

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中的类路径上将javac与多个特定的jar一起使用(冒号在冒号后不会扩展)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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