【问题标题】:Does the manifest.mf file show the version of the jar?manifest.mf 文件是否显示 jar 的版本?
【发布时间】: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


【解决方案1】:

我应该能够通过读取 manifest.mf 文件中的单个条目来找到 jar 文件的版本吗?

您“可能”能够通过这种方式找到版本号,但 JAR 文件中的版本号是可选的。 (事实上​​,即使是版本的想法也是“可选的”。Java 中没有任何东西要求您对代码进行版本控制……尽管这无疑是个好主意!)

您的“事后想法”当然看起来更简单,但您需要查看相关规范以确定它是否需要工作。

【讨论】:

    猜你喜欢
    • 2012-11-12
    • 2015-03-25
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多