• Post Reply Bookmark Topic Watch Topic
  • New Topic

Including multiple JAR files with javac in linux  RSS feed

 
Chris Mounce
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I am trying to compile a file that depends on multiple JAR files using javac on linux (Debian Wheezy). The command I'm running is as below:

javac -cp ~/dir1/dir2/commons-logging.jar:~/dir1/dir2/json-simple-1.1.1.jar:. dir3/dir4/Main.java

I have also tried putting quotes around the path, but to no avail.

javac -cp "~/dir1/dir2/commons-logging.jar:~/dir1/dir2/json-simple-1.1.1.jar:." dir3/dir4/Main.java

If I swap the order of the 2 JAR files, it always only picks up the first one. Anyone have an idea what I'm doing wrong? Thanks.
 
Chris Mounce
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to resolve this by using an asterisk on the directory, as follows:
Note: ~/ corresponds to the home directory

javac -cp ~/dir1/dir2/'*':. dir3/dir4/Main.java

Hope this helps someone else!
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't work with the quotes because they stop the ~ from being expanded.

It doesn't work without them because of another ~ expansion rule. I'm not sure of the details, but I think ~ only gets expanded at the start of a "word", not when its preceded by a non-space character, although the shell may give you the ability to change that, either globally or for a specific command. I don't know off the top of my head.

You might try

javac -cp $HOME/dir1/dir2/commons-logging.jar:$HOME/dir1/dir2/json-simple-1.1.1.jar:. dir3/dir4/Main.java


The HOME variable should contain your home dir even without you setting it, but worst case, you can to something like


home=~ javac -cp $home/dir1/dir2/commons-logging.jar:$home/dir1/dir2/json-simple-1.1.1.jar:. dir3/dir4/Main.java


Although, in the , the '*' form is simpler and cleaner anyway, so the rest of this is mostly just an academic exercise.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!