Executing a Java application in a separate process
Two hints:
System.getProperty("java.home") + "/bin/java"
gives you a path to the java executable.
((URLClassLoader) Thread.currentThread().getContextClassLoader()).getURL()
helps you to reconstruct the classpath of current application.
Then your EXECUTE.application
is just (pseudocode):
Process.exec(javaExecutable, "-classpath", urls.join(":"), CLASS_TO_BE_EXECUTED)
Whether JVM runs in User Process or Separate Process
JVM is running inside a process that was started by executing
java.exe
/javaw.exe
on Windows or thejava
executable for Unix/GNU. Its owner would be the one that runs the executable. If two java programs are running then two JVMs in different processes will be created.GC is a thread inside the JVM, see here
For example, the Java garbage collector is a daemon thread.
Java starting another Java Application
Near dupe Java execute process on linux and Difference between ProcessBuilder and Runtime.exec()
In addition to the correct points about tilde-(non-)expansion, you are passing an entire commandline as one argument to new ProcesssBuilder
. Unlike Runtime.exec()
which treats a single String
as a special case and splits into whitespace-delimited tokens mostly (but not exactly) like typical Unix shells, the ProcessBuilder
ctor does not do this. This can be seen in the exception message at the beginning of the traceback you posted. You need separate arguments like:
ProcessBuilder builder = new ProcessBuilder("java", "-jar",
System.getProperty("user.home")+"/Documents.Java/myJar.jar");
// three String's passed to vararg, compiler makes array for you
or possibly (but I don't recommend)
String line = "java -jar " + System.getProperty("user.home")+"/Documents.Java/myJar.jar";
ProcessBuilder builder = new ProcessBuilder( line.split(" ") );
// array of three String's passed directly to vararg
And replace java
by a full pathname if the desired java
program (or a link to it) isn't found first when searching the PATH in effect for your JVM process.
Running java as a separate process in windows command line through uDeploy
Try using Deamon option https://developer.ibm.com/urbancode/plugindoc/ibmucd/shell/1-2/steps/, this will run in the background and will not hold your current step for long
run class file as separate process from java code
The java
command expects a Java class name, not a filename.
So the command java E:/workspace/JNIProgram/src/JNIProgram.class
is wrong. If you try this manually from a command prompt window you'll get an error message.
The command should be something like this:
java -cp E:\workspace\JNIProgram\src JNIProgram
Note: What's after the -cp
option is the classpath, and after that the fully-qualified class name (which is just JNIProgram
, if the class is not in a package).
First make sure that you can run the command manually from the command line before you make it work from another Java program.
Related Topics
How to Click an Element in Selenium Webdriver Using JavaScript
Convert Existing Eclipse Project to Maven Project
How to Access an Iteration-Counter in Java's For-Each Loop
How to Move My Jmenubar to the Screen Menu Bar on MAC Os X
Why Doesn't Mockito Mock Static Methods
Read Content from Files Which Are Inside Zip File
How to Change the Classpath Within Java
Java Cannot Be Applied to Given Types String and Integer
Can't Make Jdbc Connection to MySQL (Using Java, Intellij, and Linux)
Compiled VS. Interpreted Languages
Access Restriction: the Type 'Application' Is Not API (Restriction on Required Library Rt.Jar)
Is It Possible in Java to Access Private Fields via Reflection
Why Is the Max Recursion Depth I Can Reach Non-Deterministic
How to Return 2 Values from a Java Method