问题
Intro
I have created a script that loops trough all installed applications on our application server, for each application finding the WEB-INF/lib-folder. Then, for all third party jar-files in the lib-folder I extract the manifest-file to find the Implementation-Version-key and its value based on the assumption that only one Implementation-Version pr. manifest.mf. So far so good, but...then some applications is dependent of XML in some way and therefore have in the lib folder jars like
- xalan.jar
- xml-apis.jar
- xerxesImpl.jar
The question
So, then off to read the Jar-file specification which I must admit does not make it clear to me: Should I be able to find the version of the jar file by just reading a single entry in the manifest.mf-file?
Example of manifest.mf
This is part of the content of the MANIFEST.MF for a xalan.jar-file found in one of the applications. This shows that it is hard to write a script which should be able to know the version of all jar files.
Manifest-Version: 1.0
Created-By: 1.3.1 (IBM Corporation)
Main-Class: org.apache.xalan.xslt.Process
Class-Path: xercesImpl.jar xml-apis.jar serializer.jar
Name: org/apache/xalan/
Comment: Main Xalan engine implementing TrAX/JAXP
Specification-Title: Java API for XML Processing
Specification-Vendor: Sun Microsystems Inc.
Specification-Version: 1.3
Implementation-Title: org.apache.xalan
Implementation-Version: 2.7.0
Implementation-Vendor: Apache Software Foundation
Implementation-URL: http://xml.apache.org/xalan-j/
Name: org/apache/xpath/
Comment: XPath engine
Implementation-Title: org.apache.xpath
Implementation-Version: 2.7.0
Implementation-Vendor: Apache Software Foundation
Implementation-URL: http://xml.apache.org/xalan-j/
Name: org/apache/xml/
Comment: DTM implementation and utilities
Implementation-Title: org.apache.xml
Implementation-Version: 2.7.0
Implementation-Vendor: Apache Software Foundation
Implementation-URL: http://xml.apache.org/xalan-j/
Afterthoughts
But - maybe I should just create a "blacklist" of which jar's to ignore such as all the XML-related jars. I found this link Xerces and Xalan locations and versions, showing that I cannot find the version of xalan.jar by looking at the manifest.mf-file. Instead I need to get the output of the Version-class.
回答1:
Should I be able to find the version of the jar file by just reading a single entry in the manifest.mf-file?
You "may" be able to find the version number that way, but version numbers in JAR files are optional. (Indeed, even the idea of a version is "optional". Nothing in Java requires you to version your code ... though it is undoubtedly a good idea!)
Your "afterthought" idea certainly looks simpler, though you would need to look at the relevant spec to decide if it is required to work.
来源:https://stackoverflow.com/questions/13222728/does-the-manifest-mf-file-show-the-version-of-the-jar