Question

This question already has an answer here:

I have an application I've built that uses a non-Java executable that it calls via 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'd like to bundle that app neatly into the jar file itself, instead of requiring it be placed outside in the same directory. Is there a way to run this app without extracting it?

If I need to drop ProcessBuilder, that would be fine, as long as it works. :)

Was it helpful?

Solution

You'd essentially be asking the OS to run an application inside of a ZIP file. I'm not aware of any way to do that without extracting it first. Even if it were a Java application, you'd need to invoke the java executable, since it knows how to parse the JAR file and access classes and resources within it.

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

OTHER TIPS

You could just bundle the executable and JAR into another zip. That way, when it is extracted by the user, everything is where you expect it to be.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top