Reputation: 6526
Using process builder to launch other Java applications in their own OS process. The implementation works on Windows 7, but not on Linux. Both machines are using Java 1.7. Here is some example code:
//Windows OK, but Linux Could not find or load main class
//weka.subspaceClusterer.MySubspaceClusterEvaluation
ArrayList<String> commands = new ArrayList<String>();
commands.add("java");
commands.add("-cp");
commands.add("\".:lib/*\"");
commands.add("weka.subspaceClusterer.MySubspaceClusterEvaluation");
procBuilder = new ProcessBuilder();
procBuilder.inheritIO();
procBuilder.command(commands);
Process proc = procBuilder.start();
Upvotes: 0
Views: 1469
Reputation: 1046
I encountered a similar issue on Mac OS X. It worked in Terminal but not in Eclipse. It worked for me if I removed quotes around the class path string. I guess Eclipse JVM does not like it when there are quotes around any of the arguments passed to ProcessBuilder.
Upvotes: 1
Reputation: 12332
Your code looks correct. It just can't find your class file. Try setting the working directory of your process:
procBuilder.directory(new File("package/structure/starts/here"));
Upvotes: 0
Reputation: 75366
The classpath separator is ;
under Windows, but :
under Unix.
Consider creating a runnable jar, where your classpath is stored in the MANIFEST.MF entry, so you can just execute java -jar whatever.jar
.
Upvotes: 1