Use javac with a few specific banks on the classpath on Linux (tilde not expandable after colon)

I am trying to compile a java source file that uses two jar files (collections of trove and apache collections) through 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 does not turn on successfully and a compilation error occurs when I use the commons library. If I cancel the import order, then compilation errors occur when I use trove. I tried to export to a variable, as well as a single and double, quoting cp string, to no avail (in such cases, none of the exports succeeded, and there are compilation errors for both the target and the community).

I have already addressed the following previous questions:

Installing several cans in java classpath path

Using multiple .jar with javac

What is the correct way to turn on two cans?

+4
source share
1 answer

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

To clarify, this is not a Java-specific issue, 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 username). The second ~ does not extend to bash, so there are problems. You expect it to expand to:

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

That is why you have the "first job, but the second not."

Looking at the bash manual:

you can see this:

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

(my selection), so only the first tilde expands, since the second tilde is not at the beginning of the word.

+11
source

Source: https://habr.com/ru/post/1394529/


All Articles