Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify an xml files in a jar file with Java

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?

like image 482
Tim Avatar asked Aug 15 '26 10:08

Tim


2 Answers

The Java API has classes for manipulating JAR files.

like image 107
Dan Dyer Avatar answered Aug 17 '26 00:08

Dan Dyer


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();
like image 44
jodonnell Avatar answered Aug 17 '26 00:08

jodonnell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!