0

I'm trying to start another Java process from my jar, and I'm using a ProcessBuilder:

File javaHome = new File(System.getProperty("java.home"), "bin");
List<String> javaList = new ArrayList<String>();

ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.redirectErrorStream(true);
processBuilder.directory(serverDir);
{
    javaList.add(javaHome + File.separator + "java");
    javaList.add("-XX:MaxPermSize=512m");
    javaList.add("-Xmx2048M");

    // -Djava.library.path="natives-win-x64/"
    javaList.add(
        String.format(                          
            "-Djava.library.path=\"natives-%s-%s/\"", 
            //Get system os, 
            //Get system arch
        )
    );

    {
        String classPath = new String();
        for (File library : scanLibrary(new File(serverDir, "libraries"))) {
            String libPath = library.getPath();
            classPath += libPath + ";";
        }

        classPath += new File(new File(serverDir, "binary"), "MainJar.jar").getPath();
        javaList.add("-classpath \\\"" + classPath + "\\\" ");
    }

    javaList.add("my.other.jar.main.class");
}
processBuilder.command(javaList);
processBuilder.start();

Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Unrecognized option: -classpath "C:\Absoulte\Path\Library.jar;C:\Absoulte\Path2\Library2.jar;C:\Absoulte\Path3\Library3.jar"

1 Answer 1

2

You're passing --classpath "..." as a single argument. I believe you should specify it as two arguments:

javaList.add("-classpath");
javaList.add("\\\"" + classPath + "\\\");

(It's not clear to me whether you really need all those backslashes, by the way... you may well find that just javaList.add(classPath) is enough, or maybe javaList.add("\"" + classPath + "\"").)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.