【发布时间】:2012-10-24 17:38:41
【问题描述】:
简介
我创建了一个脚本,该脚本循环遍历我们应用服务器上所有已安装的应用程序,以便每个应用程序找到 WEB-INF/lib 文件夹。然后,对于 lib 文件夹中的所有第三方 jar 文件,我 extract the manifest-file 找到 Implementation-Version-key 及其值,基于 只有一个 Implementation-Version pr 的假设. manifest.mf。到目前为止一切都很好,但是......然后一些应用程序以某种方式依赖于 XML,因此在 lib 文件夹中有类似的 jars
- xalan.jar
- xml-apis.jar
- xerxesImpl.jar
问题
所以,然后去阅读Jar-file specification,我必须承认这并没有让我明白:我是否能够通过读取 manifest.mf 文件中的单个条目来找到 jar 文件的版本?
manifest.mf 示例
这是在其中一个应用程序中找到的 xalan.jar 文件的 MANIFEST.MF 内容的一部分。这说明很难写出一个能知道所有jar文件版本的脚本。
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/
事后思考
但是 - 也许我应该创建一个“黑名单”,其中包含要忽略的 jar,例如所有与 XML 相关的 jar。我找到了这个链接Xerces and Xalan locations and versions,显示通过查看manifest.mf-file 找不到xalan.jar 的版本。相反,我需要获取版本类的输出。
【问题讨论】:
-
看看jcabi-manifests,它有一个实用类,可以帮助你一次性读取类路径中所有可用的
MANIFEST.MF
标签: java jar specifications manifest.mf