views:

425

answers:

2

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. :)

+1  A: 

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.

Rob H
I figured as much. I could probably have it check if the folder exists, and if not, it will extract it from the jar and then execute it. Thanks!
Ken
+1  A: 

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.

geowa4