Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use javac with multiple specific jars on classpath in Linux (tilde doesn't expand after colon)

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?

like image 775
jonderry Avatar asked Feb 03 '12 02:02

jonderry


1 Answers

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:

$ echo ~/.bashrc:~/.bashrc

You should get something like:

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

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

Looking at the bash manual:

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

you can see this:

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.

like image 72
icyrock.com Avatar answered Oct 13 '22 00:10

icyrock.com