java 查看字节码,如何查看Java的字节码?

本文介绍了在 Eclipse 中查看 `.class` 文件字节码的方法。默认情况下,按下 F3 键会尝试打开源代码视图,如果找不到源代码,则显示类似于 `javap` 的反汇编视图。若想直接查看反汇编视图,可能需要安装提供类似功能的 Eclipse 插件,或者配置外部工具来运行 `javap` 命令。但作者表示并未发现直接的快捷键用于跳转到字节码视图。
摘要由CSDN通过智能技术生成

Sometimes, in Eclipse , i press a combination of keys which take me to the editor page that shows contents of my .class file (bytecode). I never seem to be able to remember what that key combination is.

Can someone please let me know?

Or in other words, how can one see own bytecode?

解决方案

Eclipse's default class file viewer shows the source (see VonC's answer) if it has been associated with the binaries, otherwise it gives a javap-like view of the class (with an option to attach source). I'm guessing it's the latter that you are looking for.

I've never found a way to cleanly force Eclipse to show that output rather than the linked source. What you probably want is an Eclipse plug-in that provides Javap like functionality (or an interface to javap). Look for plugins stating they "disassemble" (as opposed to "decompile," like jad).

Barring a plug-in, you could probably configure an external tool to perform javap but it might not play nicely with other eclipse features.

Edit: Let me be clear about the above: If you hit F3, Eclipse does the following (generally, the actual procedure might be slightly different):

Resolves the target (if you are selecting a Java file, it will be the Java file itself; if you are selecting or your cursor is over a class name it will be the class declaration, similar for a method declaration, etc).

Searches the build path (same project first) for a Java file containing the target. If found, opens up an writable editor displaying that Java source file.

For class/method declarations, it continues searching references on your build path for a class file that contains the declaration. If it is found, then

a) If the class file has had source attached to it, open up a read-only editor of the linked Java file.

b) If the class file does not have source attached to it, then open up a read-only panel showing the disassembled (javap-like) bytecode of the compiled class file.

My guess would be that you're thinking there's a dedicated key sequence to 3.b), but I don't think there is. But again, I would love to be proven wrong here.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值