Running a jar executable using ProcessBuilder

I have an application that I created that uses a non-Java executable that it calls through ProcessBuilder:

ProcessBuilder pb = new ProcessBuilder(invocation);
pb.redirectErrorStream(true);
Process proc = pb.start();


InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);


However, I would like to simply link this application to the jar file itself, instead of requiring it to be placed in the same directory. Is there a way to launch this application without extracting it?

If I need to drop the ProcessBuilder it will be ok if it works. :)

+2


source to share


2 answers


Basically, you are asking the OS to run the application inside a ZIP file. I don't know how to do this without extracting it first. Even if it is a Java application, you will need to call the java executable as it knows how to parse the JAR file and access the classes and resources inside it.



The only fairly light workaround I can think of is to extract the contents of the JAR into a temporary folder and run the program from there. This can be done programmatically using the classes in java.util.zip .

+5


source


You can just link the executable and JAR with a different zip. That way, when it's checked out by the user, everything will be where you expect it to be.



+1


source







All Articles