Reputation: 683
Well netbeans Java 7u17 project. I'm trying to execute an external jar file that has dependencies on the following way:
ProcessBuilder pb = new ProcessBuilder(new String[]{"java", "-jar", String.format("%s %s", path, cmde)});
pb.redirectErrorStream(true);
Process proc = pb.start();
And when I execute this application I get the following error message:
Error: Unable to access jarfile C:/Users/XXXX/Documents/SampleApplication/ProcessTest/proc.jar -k
The jar file has its depenedcies (other jar files) right next to it in a folder called lib. When I open up PowerShell or Command Prompt and manually enter
java -jar C:/Users/XXXX/Documents/SampleApplication/ProcessTest/proc.jar -k
The application is executed flawlessly. Why not from my java application? I tried numerous answers for similar problem from stack overflow but none of them worked. Some example: - Restarted netbeans - Closed & Reopened project - Rebuilt proc.jar
thanks for every help - Joey
Upvotes: 1
Views: 2322
Reputation: 161
I could not solve it neither, but I have a workaround.
Create a bat script which runs your jar and execute that bat file like:
ProcessBuilder pb = new ProcessBuilder("c:\\...\\runproc.bat");
EDIT:
You need to split the command arguments one by one, like:
ProcessBuilder("java", "-jar", path, arg1, arg2, ...)
Upvotes: 2
Reputation: 1
Sorry for the answer, I can't make comments yet, but maybe you should use:
//This is correct
String path = "C:\\xxx\\xxx";
//This is incorrect
String path = "C:/xxx/xxx";
I'm just assuming, since your output shows "/" instead of the windows standard "\".
Upvotes: 0