简体   繁体   中英

Starting an external Java program from a Java program

This question has been asked before but with no real answer.

I wan't to start a Java Progam form another Java Program. In my case I wan't to start the same program(2) and then exit the original program(1) while the clone is still open.

Unfortunatly I can't get this to work with ProcessBuilder

ProcessBuilder processBuilder = new ProcessBuilder("java","Programm");

Process process = processBuilder.start();

No error message, nothing happens.

I also can't run the program from the CMD in windows. javac shows several errors during compilation:

symbol not found, ...

I can start the program normally from Eclipse.

You probably aren't seeing the errors from your Process because they are sent to its own error stream. You can access the error stream using process.getErrorStream() .

I suspect the problem is that your classpath isn't properly set when invoking the java executable and it is failing to find your class or its dependencies, but it is hard to tell without seeing the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM