Reputation: 1795
I'd like to launch a jar file through an existing running Java application. I've looked into ProcessBuilder
, Runtime
and jproc
and none of them work because they all say the same error:
CreateProcess error=193, %1 is not a valid Win32 application
The way I can get it to work is by adding the command: java -jar <path of network located jar>
in any of the libraries above.
I don't want to do it this way because it messes up with location of paths and such that would run in the context of the network location if you "double clicked" the jar files directly.
Is there a way to run the jar on the network using the "default" JRE on Windows/Mac?
here is example code:
String networkLocation = "//appserver/testApp/test.jar";
// new ProcBuilder(networkLocation).withNoTimeout().run();
ProcessBuilder pb = new ProcessBuilder(networkLocation);
try
{
pb.start();
}
catch (IOException ex)
{
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
Upvotes: 0
Views: 354
Reputation: 1795
Found out how to make the working directory using jproc:
new ProcBuilder("java", "-jar", networkLocation).withNoTimeout().withWorkingDirectory(new File ("//appserver/testApp/")).run();
And also with Runtime
Runtime.getRuntime().exec(new String[]{"java","-jar", networkLocation}, null, new File("//appserver/testApp/"));
Upvotes: 2