How can I find the target Java version for a compiled class?(如何找到已编译类的目标 Java 版本?)
问题描述
读取和显示 Java .class 版本的工具
如果我有一个已编译的 Java 类,有没有办法仅从类文件中判断它的目标版本兼容性是什么?具体来说,我有许多类文件,编译为 Java 6,它们在 Java 5 下运行并给出无法识别的版本".错误.我希望能够在不运行 JVM 的情况下查看类文件并找到其目标版本兼容性.有什么想法吗?
If I have a compiled Java class, is there a way to tell from just the class file what its target version compatibility is? Specifically, I have a number of class files, compiled to Java 6, which are running under Java 5 and giving the the "Unrecognized version" error. I want to be able to look at a class file and find what its target version compatibility is without running the JVM. Any ideas?
推荐答案
我在网上找到了这个,它可以工作.
I've found this on the net and it works.
每个.class"文件都以以下:
Every '.class' file starts off with the following:
- 幻数 [4 字节]
- 版本信息 [4 字节]
已编译的.class"文件的十六进制转储使用以下每个选项揭示:
A hexdump of a '.class' file compiled with each of the following options reveals:
javac -target 1.1 ==> CA FE BA BE 00 03 00 2Djavac -target 1.2 ==> CA FE BA BE 00 00 00 2Ejavac -target 1.3 ==> CA FE BA BE 00 00 00 2Fjavac -target 1.4 ==> CA FE BA BE 00 00 00 30
javac -target 1.1 ==> CA FE BA BE 00 03 00 2D
javac -target 1.2 ==> CA FE BA BE 00 00 00 2E
javac -target 1.3 ==> CA FE BA BE 00 00 00 2F
javac -target 1.4 ==> CA FE BA BE 00 00 00 30
也许您可以使用此信息编写自己的.class"文件版本检查实用程序,使用 Java,或者可能是脚本或外壳语言 ;) !
Perhaps you could use this information to write your own '.class' file version checking utility, using Java, or perhaps a scripting or shell language ;) !
我希望这会有所帮助.
安东尼·博拉
来自:http://bytes.com/groups/java/16603-how-determine-java-bytecode-version
这篇关于如何找到已编译类的目标 Java 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何找到已编译类的目标 Java 版本?
基础教程推荐
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
