1

はじめに

アプリケーションサーバーにインストールされているすべてのアプリケーションをループするスクリプトを作成し、アプリケーションごとに WEB-INF/lib-folder を見つけます。次に、lib-folder 内のすべてのサード パーティの jar ファイルについて、マニフェスト ファイルを抽出して、Implementation - Version pr. マニフェスト.mf。これまでのところは問題ありませんが、一部のアプリケーションは何らかの形で XML に依存しているため、lib フォルダーに次のような jar が含まれています。

  • xalan.jar
  • xml-apis.jar
  • xerxesImpl.jar

質問

それでは、Jar ファイルの仕様を読んでもはっきりとはわかりません。manifest.mf ファイルの 1 つのエントリを読むだけで、jar ファイルのバージョンを見つけることができるのでしょうか?

manifest.mf の例

これは、アプリケーションの 1 つで見つかった 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/

後付け

しかし、XML関連のすべてのjarファイルなど、無視するjarファイルの「ブラックリスト」を作成する必要があるかもしれません。このリンクXerces と Xalan の場所とバージョンを見つけました。これは、manifest.mf ファイルを見て xalan.jar のバージョンを見つけることができないことを示しています。代わりに、Version クラスの出力を取得する必要があります。

4

1 に答える 1

1

manifest.mf-file の 1 つのエントリを読み取るだけで、jar ファイルのバージョンを見つけることができますか?

その方法でバージョン番号を見つけることができるかもしれませんが、JAR ファイルのバージョン番号はオプションです。(実際、バージョンの考え方でさえ「オプション」です。Java では、コードのバージョンを指定する必要はありません...ただし、それは間違いなく良い考えです!)

「後付け」のアイデアは確かに簡単に見えますが、関連する仕様を調べて、それが機能する必要があるかどうかを判断する必要があります。

于 2012-11-04T21:10:03.913 に答える