1

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?

3 Answers 3

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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();

5 Comments

As I mention, the bundled jre doesn't actually contain a java executable
@SimonZhu "As I mention, the bundled jre doesn't actually contain a java executable" - This does not matter. The program was started with a JRE installed on your system, and from within java this property always points to the currently running Java installation, regadless of where your system wide, or shell specific $JAVA_HOME points to.
No, the program runs in the bundled jre, which doesn't contain a java executable. In other words, System.getProperty("java.home") + "bin/java" does not exist.
@SimonZhu "No, the program runs in the bundled jre, which doesn't contain a java executable." that's nonsense. no java executable -> no JRE end of message!
I suggest you look up embedded JRE's. If you want, you can take a look at the application in question here. Good luck finding the java executable.
0

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)

1 Comment

As I said to Timothy and I mention in my question, the bundled jre doesn't contain an executable java. The filepath returned by System.getProperty("java.home") does not even contain a bin folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.