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?
The Java API has classes for manipulating JAR files.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With