I’m executing the java binary from one of my classes, and a ClassNotFoundException gets thrown:
Results of executing:/usr/bin/java -classpath "/home/geo" Geoline
Error stream:
Exception in thread "main" java.lang.NoClassDefFoundError: Geoline
Caused by: java.lang.ClassNotFoundException: Geoline
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
Could not find the main class: Geoline. Program will exit.
Output stream:
The Geoline class is located at /home/geo/Geoline.java. The thing is, no matter where in the filesystem I’m located, if I execute the same command manually, the class is executed. Why isn’t the same thing happening when the binary is executed with Runtime.getRuntime().exec?
edit: here’s the output generated with the verbose flag on: pastie link
edit: here’s the contents of the file :
public class Geoline {
public static void main(String[] args) {
System.out.println("blabla");
}
}
It is quite hard to tell what’s going on because you didn’t post the code.
However this is my most educated guess.
You’re trying to run the whole command into a java String and the java interpreter is not recognizing them as different arguments.
Try packaging them all in a String[]
So instead of
Try with:
Or, you could post your actual code and we can see what’s going on.
EDIT
This is my attempt. I create the RunIt.java class which is basically Runtime.exec as I suggested and Hello.java which pretty much says Hello + args[0]
Here’s the ouput: