tags:

views:

1738

answers:

3

I currently am tasked with updating an XML file (persistance.xml) within a jar at a customers site. I can of course unjar the file, update the xml, then rejar the file for redeployment. I would like to kind these command line operations in a Swing App so that the person doing it does not have to drop to the command line. Any thoughts on a way to do this programatically?

+4  A: 

The Java API has classes for manipulating JAR files.

Dan Dyer
+1  A: 

You can use Java's ZipFile and ZipEntry classes to read the contents of a JAR file, then use ZipOutputStream to create a new one.

Bill the Lizard
+1  A: 

Sure:

File tmp = new File ("tmp");
tmp.mkdirs();
Process unjar = new ProcessBuilder ("jar", "-xf", "myjar.jar", tmp.getName ()).start();
unjar.waitFor();
// TODO read and update persistence.xml
Process jar = new ProcessBuilder ("jar", "-cf", "myjar.jar", tmp.getName()).start();
jar.waitFor();
jodonnell