Reputation: 498
I want to start a separate process from my java program to run another java program using same JRE that the current java program is executing in. Normally, I could get the path to the java executable using System.getProperty
, but the java program is running in a bundled jre (Mac app package) which doesn't actually contain a java executable. Therefore, I'm wondering if there is there any API to directly run a Java program in a separate process?
Upvotes: 1
Views: 938
Reputation: 21
Javapackager from Java version 9 on includes the bundler argument -strip-native-commands
which leaves the executables in the bundled JRE. Just include the option:
-Bstrip-native-commands=false
Upvotes: 1
Reputation: 2718
This may give a better picture.
Get the Java executable using below.
System.getProperty("java.home") + "/bin/java"
ReConstruct the class path,
((URLClassLoader() Thread.currentThread().getContextClassLoader()).getURL()
From here, you can start the new process using
Process.exec(javaExecutable, "-classpath", urls.join(":"), CLASS_WIH_MAIN)
Upvotes: 0
Reputation: 15624
The API is public hosted here: http://docs.oracle.com/javase/8/docs/api/
and the information you are looking for cons from the System
utility class:
All available properties are listed here: http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getProperties--
The current JVMs location is available via "java.home".
So what your looking for is:
String javaPath = new File( System.getProperty("java.home"),"bin/java").absolutePath();
Upvotes: 0