Java - 哪个版本也构建了 .jar 文件?
有没有办法找出用于构建 .jar 文件的 JDK 版本?
Is there a way to find out the JDK version used to build a .jar file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有没有办法找出用于构建 .jar 文件的 JDK 版本?
Is there a way to find out the JDK version used to build a .jar file?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
这不可能可靠地实现,因为您甚至不需要 JDK 来构建 JAR 文件 - 它只是一个包含类和清单文件的 ZIP 文件。
您可以找到的是类文件的版本使用格式。主要版本号映射到主要JDK版本:
但是,java编译器可以选择使用先前版本的类文件格式,这经常用于实现向下兼容性。但是,如果您发现类文件版本主编号为 50,您就知道这些类肯定不是使用 Java 5 或更早版本的 JDK 编译的。
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.
What you can find out is what version of the class file format is used. The major version number maps to majorJDK releases:
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.
大多数 jar 是使用 jdk 打包提供的“jar”工具构建的。
在 SUN 的 JDK 中,提供的“jar”工具将在嵌入的 META-INF/MANIFEST.MF 文件中添加“Created-By”行。
该行将指定创建 JAR 的 JDK 版本(在我的例子中为“Created-By: 1.6.0_17 (Sun Microsystems Inc.)”)
其他 Java 供应商也倾向于这样做。
Most jars are built using the provided "jar" tool packaged with the jdk.
In SUN's JDK the provided "jar" tool will add a "Created-By" line in the embedded META-INF/MANIFEST.MF file.
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.)")
Other Java vendors tend to do the same.
您可以从 jar 文件中提取类文件并使用以下命令:
应该为您提供类文件的版本号。
You can extract the class files from the jar file and use the following command:
Should give you the version number of the class files.
在 Jars MANIFEST.MF 中可能有一个 Build-Jdk 属性,这应该就是您正在寻找的。
In the Jars MANIFEST.MF there may be a Build-Jdk property which should be what you're looking for.