Java - 哪个版本也是构建的 .jar 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4440896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java - Which version was a .jar file built too?
提问by Ash Burlaczenko
Is there a way to find out the JDK version used to build a .jar file?
有没有办法找出用于构建 .jar 文件的 JDK 版本?
采纳答案by Michael Borgwardt
That's not possible reliably, since you don't even need a JDK to build a JAR file - it's just a ZIP file with the classes and a manifest file inside.
这是不可能的,因为您甚至不需要 JDK 来构建 JAR 文件——它只是一个包含类和清单文件的 ZIP 文件。
What you can find out is what version of the class file formatis used. The major version number maps to majorJDK releases:
您可以查明使用的是哪个版本的类文件格式。主要版本号映射到主要JDK 版本:
J2SE 6.0 = 50 (0x32 hex)
J2SE 5.0 = 49 (0x31 hex)
JDK 1.4 = 48 (0x30 hex)
JDK 1.3 = 47 (0x2F hex)
JDK 1.2 = 46 (0x2E hex)
JDK 1.1 = 45 (0x2D hex)
However, the java compiler has an option to use the class file format of a previous version, which is frequently used to achieve downwards compatibility. But if you find a class file version major number of 50, you know that the classes were definitely not compiled with a Java 5 or earlier JDK.
但是,java 编译器可以选择使用以前版本的类文件格式,这经常用于实现向下兼容。但是,如果您发现类文件版本主要编号为 50,您就会知道这些类肯定不是用 Java 5 或更早版本的 JDK 编译的。
回答by Edwin Buck
Most jars are built using the provided "jar" tool packaged with the jdk.
大多数 jar 是使用与 jdk 打包在一起的提供的“jar”工具构建的。
In SUN's JDK the provided "jar" tool will add a "Created-By" line in the embedded META-INF/MANIFEST.MF file.
在 SUN 的 JDK 中,提供的“jar”工具将在嵌入的 META-INF/MANIFEST.MF 文件中添加“Created-By”行。
That line will specify the version of the JDK that created the JAR (in my case "Created-By: 1.6.0_17 (Sun Microsystems Inc.)")
该行将指定创建 JAR 的 JDK 版本(在我的例子中是“Created-By: 1.6.0_17 (Sun Microsystems Inc.)”)
Other Java vendors tend to do the same.
其他 Java 供应商也倾向于这样做。
回答by Jim
In the Jars MANIFEST.MF there may be a Build-Jdk property which should be what you're looking for.
在 Jars MANIFEST.MF 中,可能有一个 Build-Jdk 属性,这应该是您要查找的内容。
回答by Nayeem Zen
You can extract the class files from the jar file and use the following command:
您可以从 jar 文件中提取类文件并使用以下命令:
javap -verbose SomeClass | grep major
Should give you the version number of the class files.
应该给你类文件的版本号。