0

When I try to execute a jar from command line it works fine. I am trying to execute that same jar in another java program like so:

ProcessBuilder pb = new ProcessBuilder("java", "-Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools.jar"); pb.start() 

However, this is giving me a ClassNotFoundException

ERR>Exception in thread "main" java.lang.NoClassDefFoundError: -Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools/jar" ERR>Caused by: java.lang.ClassNotFoundException: -Xmx1024m -Xms1024m -DTOOLS_DIR=".home.IM.work.dist" -Daoi=whole -jar ".home.IM.work.dist.idt_tools.jar" ERR> at java.net.URLClassLoader$1.run(URLClassLoader.java:202) ERR> at java.security.AccessController.doPrivileged(Native Method) ERR> at java.net.URLClassLoader.findClass(URLClassLoader.java:190) ERR> at java.lang.ClassLoader.loadClass(ClassLoader.java:307) ERR> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) ERR> at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ERR>Could not find the main class: -Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools.jar". Program will exit. 

Why does it think that is a class? Can you not specify your arguments in one long string?

1 Answer 1

6

Makes sense to me.

Perhaps you didn't intend to run a class called "-Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools.jar" perhaps you meant those to be seperate arguments?

try

ProcessBuilder pb = new ProcessBuilder("java", "-Xmx1024m", "-Xms1024m", "-DTOOLS_DIR=/home/IM/work/dist", "-Daoi=whole", "-jar", "/home/IM/work/dist/idt_tools.jar"); 
Sign up to request clarification or add additional context in comments.

6 Comments

I am not sure if this is the same or not, but i actually took my whole command, split it with " " as the delimiter, and tried to run it - now I get that it is "unable to access jarfile"
It should say "Unable to access jarfile {jarfile}" Can you check this jar file is accessible by the user trying to run the process? e.g. if the user of the process is not IM, that user might not be able to access /home/IM/
@Peter Lawrey - so, it appears your saying that trying to run a .class , contained in a .jar file, which has a Main method, BUT that .class is not registered in the manifest as the main method, that the .class is effectively not runnable without extracting the .jar???
@djangofan, If you want to run a main in a jar, you can just call java -cp jarfile.jar my.MainClass If you want it to pick the MainClass automagically, you have to have it registered in the MANIFEST
I decided to use a project called "one-jar" , which allows me to add .jar resources into the executable jar that are accessible by the main method. so, i dont need to add certain jars to the classpath either. its nice and automagical.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.