Reputation: 1403
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"
Upvotes: 0
Views: 7472
Reputation: 1503869
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 + "\"")
.)
Upvotes: 2