0

I am having trouble running a JAR file from terminal which has both native and .jar dependencies. Okay, my goal isn't to run it from the terminal, but to run it as a separate process with Java's Runtime.getRuntime().exec function, but if I can't run it from the terminal, then I also can't run it via. The JAR file I am trying to run depends on a number of other jar files as well as a number of .so libraries. I'm trying to put put all the .jar dependencies and .so dependencies in their own folders and then run the jar file with:

java -cp /home/johnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/* -Djava.library.path=/home/johnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/lib/native/linux-64/* -jar /home/johnmichaelreed/NetBeansProjects/SendReceive/dist/SendReceive.jar

Where "/home/johnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/" contains all the JAR files and "/home/johnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/lib/native/linux-64/" contains all the .so files and the main JAR file to run is "/home/johnmichaelreed/NetBeansProjects/SendReceive/dist/SendReceive.jar", but I keep getting this error:

Error: Could not find or load main class 
.home.johnmichaelreed.Desktop.Dropbox.Libjitsi_linux_64.some-compressed-jar-file.jar

Where some-compressed-jar-file.jar is one of the .jar files that my application is supposed to use.

Here's my Java JAR dependencies folder:

Java Jar dependencies

And here's my native libraries dependencies folder:

enter image description here

UPDATE:

Okay, this is the solution:

java -Djava.library.path=/home/johnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/lib/native/linux-64 -cp '/home/johnmichaelreed/NetBeansProjects/SendReceive/dist/SendReceive.jar:/home/j‌​ohnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/*' Main

With attempt at command line args:

java -Djava.library.path=/home/johnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/lib/native/linux-64 -cp '/home/johnmichaelreed/NetBeansProjects/SendReceive/dist/SendReceive.jar:/home/j‌​ohnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/*' Main "arg"

  • I'd say the shell expansion of your command (resolving the *) makes the full line incorrect, and java takes one of your jar file as the class name. I'm not sure you can use * in your case, but try wrapping the parameters in quotes. – JP Moresmau May 18 '15 at 15:47

1 Answers1

0

You can't use -jar and -cp at the same time.

What you can do, is adding your jar to the classpath and then specify your Main class to run. You can also specify the jar dependencies within the manifest of your jar.

Please have a look here for more details.


Assuming your Main class is in called Main and in the package foo.bar, then a possible call may look like:

java -cp "/home/johnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/*;/home/johnmichaelreed/NetBeansProjects/SendReceive/dist/SendReceive.jar" -Djava.library.path="/home/johnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/lib/native/linux-64/*" foo.bar.Main
Community
  • 1
  • 1
MalaKa
  • 3,734
  • 2
  • 18
  • 31
  • Oh. So I should do something like " java -Djava.library.path=/home/johnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/lib/native/linux-64/* -cp '/home/johnmichaelreed/NetBeansProjects/SendReceive/dist/SendReceive.jar:/home/johnmichaelreed/Desktop/Dropbox/Libjitsi_linux_64/*' main.Main " to specify that I want the native Linux 64 folder to hold .so files, that I want to run my application's jar and everything in the Libjitsi_linux_64 libraries folder, and that the name of the class containing the main method is called "Main". –  May 18 '15 at 15:56
  • Also, the * wildcard isn't recursive, right? Like if I have the same .jar file in the libraries folder and in a subfolder of the libraries folder, it won't load that jar file twice. –  May 18 '15 at 16:00
  • Okay, you were faster than my edit, you're welcome :) – MalaKa May 18 '15 at 16:04
  • Oh wait. It's running, but it isn't loading the native libraries. How do you do it with native libraries and also command line args? –  May 18 '15 at 18:11
  • Hm, have you tried to turn around the arguments? So first the `-Djava.library.path`? – MalaKa May 18 '15 at 18:24
  • I got it working from the terminal - just had to wrap the args in quotation marks. Thank you. –  May 19 '15 at 00:22