How to Print Text File Content Inside a Jar File
Join the DZone community and get the full member experience.Join For Free
Have you ever wonder what's the exact version of your ojdbc6.jar that you have? All the jar files will contain a META-INF/MANIFEST.MF file, and chances are the version will be in it! You may try using $JAVA_HOME/bin/jar -xvf to extract the jar and then view the text file. But afterward you would have to clean up the extracted file so not to liter.
However, if you got Groovy, you can print any text file inside a jar without above mess.
file = new File(args) name = args.size() > 1 ? args : "META-INF/MANIFEST.MF" jar = new java.util.jar.JarFile(file) entry = jar.getEntry(name) istream = jar.getInputStream(entry) println(istream.text) istream.close()
You may use this script like this:
$ groovy printjar.groovy /path/to/objdbc6.jar # Or give an explicit entry name $ groovy printjar.groovy $JBOSS_HOME/jboss-modules.jar 'META-INF/maven/org.jboss.modules/jboss-modules/pom.properties'
Published at DZone with permission of Zemian Deng, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.