View Contents Of Jar File4/15/2021
The next code listing shows a simple Groovy script that makes use of Javas JAR-handling classes JarFile, Manifest, and Attributes to print the contents of a given JARs manifest file to standard output.
View Contents Of Jar File Zip Command WithThe post looks specifically at how to use Linux unzip command with its -p option to display the contents of a JAR files MANIFEST.MF file to sdtout in a single command and without any new files that need to be cleaned up.The post Viewing the MANIFEST.MF from a jar in a single command provides an example of how to use the Linux unzip command and its -p option.I adjust that example slightly for my own example here that I will use in demonstrating several ways to access the contents of the MANIFEST.MF file.For my example, I will be looking at the MANIFEST.MF file contained in the jdiff.jar I have built locally on my system. Although JDiff comes with a pre-built JAR, I have been building and using it locally with Java 7 and thought it provided as good as any JAR upon which to try viewing the manifest file. This JAR s manifest file can be viewed in Linux with the following unzip command: unzip -p jdiff.jar META-INFMANIFEST.MF. Because the -p option specifies that the unzip command should write its output to standard output rather than to an actual file, there is no need to clean up any files. The author of the blog post Viewing the MANIFEST.MF from a jar in a single command mentions that the old way to view a manifest file was often to create a temporary directory, copy the JAR of interest into that temporary directory, change directory to that temporary directory, unzip the JAR files contents, view the file of interest, and then remove the temporary directory. That post demonstrates the commands that would be done for this approach. Fortunately, the jar command provides a few places to make things a little easier. Specifically, jar allows us to explicitly specify a subset of files we want extracted. This means that instead of making a temporary directory to hold all the extra stuff that we dont want to clutter our current directory, we could simple extract the single file with the jar command and this is often acceptable if its only one file. The single file is extracted with the command jar xvf jdiff.jar META-INFMANIFEST.MF and then all thats left to be done is to run a command like (in DOS) type META-INFMANIFEST.MF ( cat or less or more could be used in Linux). The only residue left from this is a META-INF directory with the desired MANIFEST.MF file inside of it, but there is still something left to be removed. The Firefox web browser can render more than simple HTML and text files as is demonstrated in the post View Contents of ZIPJAR File using Firefox. That post demonstrates a simple example using Firefox 3, but this feature is also available in Firefox 4 as shown in the next three screen snapshots that show opening of the JAR, drilling down into the META-INF directory and then displaying the contents of the MANIFEST.MF file. The screen snapshots shown above demonstrate how easy it is to see the contents of the JAR in the Firefox web browser The only special treatment of the URL required was to specify jar:file at the beginning of the URL and to end it with a exclamation point. In my case, it was: jar: file:C:jdiff-1.1.1jdiff.jar and the more general syntax is: jar:file. The Java IDEs are obvious choices for easily seeing the contents of a manifest file. The following screen snapshot demonstrates viewing the manifest file. Other Java IDEs provide similarly easy-to-use viewing of manifest files within a JAR. ![]() If a JAR is on an Eclipse projects build path, it can be opened up to see the JARs contents as shown in the next screen snapshot. When it comes to the tools for Java development, Groovy is never far from my mind as a source for building useful tools.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |