-1

I've tryied to restart my Java Application with this code:

public static void restartApplication() throws URISyntaxException, IOException {
    final File currentJar = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());

    /* is it a jar file? */
    if(!currentJar.getName().endsWith(".jar"))
        return;

    /* Build command: java -jar application.jar */
    final ProcessBuilder builder = new ProcessBuilder("java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main");
    builder.inheritIO();
    builder.start();

    System.exit(0);
}

When I type the command into my command panel it works totaly fine. So what is the Error here? Output

java.io.IOException: Cannot run program "java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main": error=2, No such file or directory

1

1 Answer 1

0

final ProcessBuilder builder = new ProcessBuilder("java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main");

This line is false. Java/The OS will look for an executable called java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main.exe. You have to separate the arguments like this:

final ProcessBuilder builder = new ProcessBuilder("java", "-Xmx512m" ,"-cp", "/opt/Nils.jar", "dev.keksstudios.core.Main");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.