问题描述
我创建了一个脚本,循环遍历应用程序服务器上的所有已安装的应用程序,用于查找WEB-INF / lib文件夹的每个应用程序。然后,对于lib文件夹中的所有第三方jar文件,我以找到 Implementation-Version -key及其值,假设只有一个实现版本PR。 MANIFEST.MF 。到目前为止一直很好,但是......然后一些应用程序以某种方式依赖于XML,因此在lib文件夹中就像
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
所以,然后关闭以阅读我必须承认并不清楚我:我应该能够找到版本的通过读取manifest.mf文件中的单个条目来获取jar文件?
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?
这是xalan的MANIFEST.MF内容的一部分。在其中一个应用程序中找到jar文件。这表明很难编写一个应该能够知道所有jar文件版本的脚本。
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
但是 - 也许我应该创建一个黑名单,其中要忽略哪些jar,例如所有与XML相关的jar。我发现此链接,显示我通过查看manifest.mf文件找不到xalan.jar的版本。相反,我需要得到版本类的输出。
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.
推荐答案
您可能能够找到那种版本号,但JAR文件中的版本号是可选的。 (实际上,即使是版本的概念也是可选的。在Java中没有任何东西要求你对你的代码进行版本控制......虽然这无疑是一个好主意!)
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.
这篇关于manifest.mf文件是否显示jar的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!