Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. ProcessBuilder pb = new ProcessBuilder("java", "Second App Main Class Name");
  2. pb.start();
  3.  
  4. public int exec(Class<?> clazz) throws IOException,
  5. InterruptedException {
  6. String javaHome = System.getProperty("java.home");
  7. String javaBin = javaHome +
  8. File.separator + "bin" +
  9. File.separator + "java";
  10.  
  11. /* This is where you want to set up your Classpath for the second app */
  12. String classpath = System.getProperty("java.class.path");
  13. String className = clazz.getCanonicalName();
  14.  
  15. ProcessBuilder builder = new ProcessBuilder(
  16. javaBin, "-cp", classpath, className);
  17.  
  18. Process process = builder.start();
  19. process.waitFor();
  20. return process.exitValue();
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement