• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extracting a JAR without a JDK installed.

 
Joshua Napier
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone,

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.

Two questions:
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?
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know a JAR file has the same format as a ZIP file, so if you have a tool that can zip/unzip, it can also unpack JAR files.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper is correct; any unzipping tool will extract a .jar.

And welcome to the Ranch
 
Joshua Napier
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain why are you allowing/expecting your user to manually open and edit the contents of a jar file? Does this jar file contain Java class files as well?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic