如何查看jar文件的版本?
我目前正在开发一个 J2ME 抛光应用程序,只是对其进行增强。我发现很难获取 jar 文件的确切版本。 有什么方法可以找到类中完成的导入的 jar 文件的版本吗?我的意思是,如果你有一些东西,请导入 xyz;我们可以知道 xy 包所属的 jar 版本吗?
I am currently working on a J2ME polish application, just enhancing it. I am finding difficulties to get the exact version of the jar file.
Is there any way to find the version of the jar file for the imports done in the class? I mean if you have some thing, import x.y.z; can we know the version of the jar x.y package belongs to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
解压 JAR 文件并查找清单文件 (
META-INF\MANIFEST.MF
)。 JAR 文件的清单文件可能包含版本号(但并不总是指定版本)。Decompress the JAR file and look for the manifest file (
META-INF\MANIFEST.MF
). The manifest file of JAR file might contain a version number (but not always a version is specified).您需要解压缩它并检查其
META-INF/MANIFEST.MF
文件,例如或更具体:
You need to unzip it and check its
META-INF/MANIFEST.MF
file, e.g.or more specific:
只是为了扩展上面的答案,在 JAR 中的 META-INF/MANIFEST.MF 文件中,您可能会看到一行:
Manifest-Version: 1.0
← 这是 NOT jar 版本号!您需要查找
Implementation-Version
,如果存在的话,它是一个自由文本字符串,因此完全取决于 JAR 的作者您将在其中找到什么。另请参阅 Oracle 文档 和 软件包版本规范
Just to expand on the answers above, inside the META-INF/MANIFEST.MF file in the JAR, you will likely see a line:
Manifest-Version: 1.0
← This is NOT the jar versions number!You need to look for
Implementation-Version
which, if present, is a free-text string so entirely up to the JAR's author as to what you'll find in there.See also Oracle docs and Package Version specificaion
只是为了完成上面的答案。
清单文件位于
META-INF\MANIFEST.MF
路径下的 jar 内。您可以在任何支持 zip 的归档程序中检查 jar 的内容。
Just to complete the above answer.
Manifest file is located inside jar at
META-INF\MANIFEST.MF
path.You can examine jar's contents in any archiver that supports zip.
每个 jar 版本都有一个唯一的校验和。您可以计算 jar 的校验和(没有版本信息)并将其与 jar 的不同版本进行比较。我们还可以使用校验和来搜索 jar。
请参考这个问题来计算校验和:
计算我计算机上文件的校验和的最佳方法是什么?
Each jar version has a unique checksum. You can calculate the checksum for you jar (that had no version info) and compare it with the different versions of the jar. We can also search a jar using checksum.
Refer this Question to calculate checksum:
What is the best way to calculate a checksum for a file that is on my machine?
基本上,您应该使用 java.lang.Package 类,它使用类加载器为您提供有关类的信息。
示例:
我认为 logback 已知使用此功能来跟踪其生成的堆栈跟踪中每个类的 JAR 名称/版本。
另请参见 http://docs.oracle .com/javase/8/docs/technotes/guides/versioning/spec/versioning2.html#wp90779
Basically you should use the
java.lang.Package
class which use the classloader to give you informations about your classes.example:
I think logback is known to use this feature to trace the JAR name/version of each class in its produced stacktraces.
see also http://docs.oracle.com/javase/8/docs/technotes/guides/versioning/spec/versioning2.html#wp90779
我想我会给出一个更新的答案,因为这个问题在搜索中的出现率仍然很高。
检查 CLi JAR 版本:
在 CLi jar 文件上运行以下命令:
示例输出:
上面列出了 CLi 版本。
要获取服务器版本,请运行以下命令:(
以上内容将根据您的身份验证实现而有所不同,请相应更改)
示例输出:
Thought I would give a more recent answer as this question still comes up pretty high on searches.
Checking CLi JAR Version:
Run the following on the CLi jar file:
Example Output:
The CLi version is listed above.
To get the Server Version, run the following:
(the above will vary based on your implementation of authentication, please change accordingly)
Example Output:
这个简单的程序将列出 jar 版本的所有情况,即
未找到 Manifest 文件
它使用 javaxt-core jar,可以从 http: //www.javaxt.com/downloads/
This simple program will list all the cases for version of jar namely
Manifest file not found
It uses the javaxt-core jar which can be downloaded from http://www.javaxt.com/downloads/
尝试以下两种方法
我迟到了,但您可以使用这些所需的类
这些方法让我访问 jar 属性。我喜欢向后兼容并使用最新的。所以我使用了这个,
当你使用maven并且需要已知类的pom详细信息时,这很有效。希望这有帮助。
I'm late this but you can try the following two methods
using these needed classes
These methods let me access the jar attributes. I like being backwards compatible and use the latest. So I used this
This works well when you are using maven and need pom details for known classes. Hope this helps.
对于 Linux,请尝试以下操作:
find . -name "YOUR_JAR_FILE.jar" -exec zipgrep "实现版本:" '{}' \;|awk -F ': ' '{print $2}'
For Linux, try following:
find . -name "YOUR_JAR_FILE.jar" -exec zipgrep "Implementation-Version:" '{}' \;|awk -F ': ' '{print $2}'
如果你有winrar,用winrar打开jar,双击打开文件夹
META-INF
。将MANIFEST.MF
和CHANGES
文件提取到任何位置(例如桌面)。在文本编辑器中打开提取的文件:您将看到实现版本或发布版本。
If you have winrar, open the jar with winrar, double-click to open folder
META-INF
. ExtractMANIFEST.MF
andCHANGES
files to any location (say desktop).Open the extracted files in a text editor: You will see Implementation-Version or release version.
[A] 我们可以手动提取/解压缩 jar 文件并检查 META-INF/MANIFEST.MF 文件中的 Bundle-Version 或 Implementing-Version 关键字。
[B] 在 Unix 环境中,
您可以轻松地将 grep 命令与 unzip 然后 cut 命令结合使用来获取版本。
[此解决方案确实假设 META-INF/MANIFEST.MF 中会提到版本。 (80% 机会)]
运行以下命令来获取版本。
VERSION=
unzip -p "javaPackage.jar" "META-INF/MANIFEST.MF" | grep -m1 -E "捆绑版本|实现版本:" |切 -d':' -f2 | awk '{$1=$1;print}' 2>/dev/null
;说明:
注意: - 如果您想查找多个 jar 的版本,请运行 for 循环并调用上面的脚本。
[A] Manually we can extract/unzip the jar file and check Bundle-Version or Implementation-Version keyword in META-INF/MANIFEST.MF file.
[B] In Unix environment ,
you can easily use the grep command in combination with unzip and then cut command to get the version.
[This soluction does assume that there will be version mentioned in META-INF/MANIFEST.MF . (80% chances)]
Run below command to get the VERSION.
VERSION=
unzip -p "javaPackage.jar" "META-INF/MANIFEST.MF" | grep -m1 -E "Bundle-Version|Implementation-Version:" | cut -d':' -f2 | awk '{$1=$1;print}' 2>/dev/null
;Explanation :
Note : - If you want to find version of multiple jars , then run a for loop and call above script.
从 MANIFEST 文件中过滤版本
您可以使用unzip -p my.jar META-INF/MANIFEST.MF | 。 grep '捆绑版本'
You can filter version from the MANIFEST file using
unzip -p my.jar META-INF/MANIFEST.MF | grep 'Bundle-Version'
不涉及提取 jar 文件的最佳解决方案是运行以下命令。如果 jar 文件不包含清单文件,您将收到“警告:未找到清单文件”
java -jar file.jar -v
best solution that does not involve extracting the jar files is to run the following command. If the jar file does not contain a manifest file you will get a "WARNING: Manifest file not found"
java -jar file.jar -v
你可以执行这个脚本,它会在目录中找到所有版本的jar文件:
You could execute this script, it will find all versions of jar files in a directory:
只需使用 .zip 而不是 .jar 重命名扩展名即可。然后进入META-INF/MANIFEST.MF,用记事本打开MANIFEST.MF文件。您可以在那里找到实施版本。
Just rename the extension with .zip instead of .jar. Then go to META-INF/MANIFEST.MF and open the MANIFEST.MF file with notepad. You can find the implementation version there.
可以使用命令
java -jar jarname
进行检查It can be checked with a command
java -jar jarname