You can't actually rely, within java, of there being a java executable you can find. "Start another VM from within my java app" is not something java offers naturally.
It's possible there is a space in your jar file. I strongly suggest you always use ProcessBuilder
, and use the form that takes a string array/string collection instead of one giant string, to avoid issues with spaces (that one giant string means that java will just split on spaces, and does far less massaging of the input than you may be used to from the command line, where bash does quite a lot of that.
In general calling java
or anything else relative is very iffy. You should put in a fully qualified path. Which naturally leads to the question of: Yeah, um, I have no idea where the java executable is. Right, but you have no idea that the OS knows where it is, either. On windows, it's not even the right executable (javaw
is probably what you want, which doesn't exist on other platforms). First start with the absolute path on your machine just to check that the problem is that a relative java
isn't going to do it.
Thus, start here:
public static void main(String[] args) throws Exception {
ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\Java\\Java 1.8\\javaw.exe", "-jar" "C:\\Users\\Erwann\\Desktop\\aled.jar");
Process p = pb.start();
}
fixing the path to be where your java actually lives (I just made a path up!)
Then, depending on whether that works or not, the next steps are either to figure out what's wrong with the jar, or to figure out how to obtain that path dynamically (which will not be easy, and will be a thing that will be hard to test, because it's basically system-dependent code).