This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Thank you in advance for any help you can give me, it is very much appreciated!
I am trying to build a little tool to help automate some admin tasks. I would like this tool to be easily distributed to environments that have certain software packages installed. However, part of the task is extracting a jar file, modifying some xml properties included in the jar file, and repackaging the jar file. This is easy enough using a jdk with the jar command, but I would like to not require the user of this utility to install a jdk, as the installed software packages come with a JRE, and I was hoping to use that JRE.
1. Is there a way to extract a Jar and compress a Jar using only a JRE?
2. Is this the right approach? Is there an easier way?
It isn't too easy to use, but there is a JarFile class in the java.util.jar package that can be used to read the JAR file (and unpack its contents), and a JarOutputStream (same package) to package it back up.
An alternative is to extract the XML file, then leave the file out (in a path relative to the JAR) after changing its properties. Then your app could look for the XML file in the <path relative to JAR> and use it if present - then fall back to the one stored in the JAR file if the free file is not.
Jesper is correct; any unzipping tool will extract a .jar.
And welcome to the Ranch
Joined: Nov 28, 2012
Sounds like there are two options:
1. Use the java.util.jar.JarFile class to load the file into java, do my work, write back to jar file, and exit
The only problem with this is that I will now have to do all my work in Java, which isnt horrible, but would mean I would have to throw away previous work - this may be ok, because I was going to have to rewrite it to run in unix as well anyway.
2. Use winzip, etc. The only disadvantage here is that we then require the user to install or have installed some type of zip utility. The only thing I know for sure that the user will have installed is the software we are editing, which has a JRE.
Thank you for the responses and for the welcome to the ranch - I think I'll like it here