Search code examples
javaprocessbuilder

Start runnable jar with process builder


How to write this command in process builder. I tried different combinations, but nothing worked for me.

/Users/rawfodog/Documents/OpenJRE11/Contents/Home/bin/Java -jar --module-path /Users/rawfodog/Downloads/AllLibrary --add-modules=javafx.controls,javafx.fxml /Users/rawfodog/Downloads/app.jar

EDIT

My code:

        ProcessBuilder pb = new ProcessBuilder("/Users/rawfodog/Documents/OpenJRE11/Contents/Home/bin/Java", "-jar", "--module-path /Users/rawfodog/Downloads/AllLibrary","--add-modules=javafx.controls,javafx.fxml", "/Users/rawfodog/Downloads/app.jar");
        pb.start();

Solution

  • You should separate each of the individual parameters - currently 2 arguments are joined in the "--module-path" argument:

    ProcessBuilder pb = new ProcessBuilder(
      "/Users/rawfodog/Documents/OpenJRE11/Contents/Home/bin/Java"
       , "-jar"
       , "--module-path"
       , "/Users/rawfodog/Downloads/AllLibrary"
       ,"--add-modules=javafx.controls,javafx.fxml"
       , "/Users/rawfodog/Downloads/app.jar");
    

    Also add code to check the exit status / wait for end of process:

    Process p = pb.start();
    int rc = p.waitFor();