如何查看Java的字节码? [英] How to view Java's byte code?

查看:297
本文介绍了如何查看Java的字节码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,在Eclipse中,我按组合键,将我带到编辑器页面,显示我的.class文件(字节码)的内容。我从来没有能够记住什么是组合键。



有人可以让我知道吗?



或者换句话说,如何看到自己的字节码? / p>

解决方案

如果Eclipse的默认类文件查看器与二进制文件相关联,类的javap-like视图(带有附加源选项)。我猜这是你正在寻找的后者。



我从来没有找到一种方法来干净地强迫Eclipse显示输出而不是链接的源。你可能想要的是一个Eclipse插件,它提供类似Javap的功能(或javap的接口)。寻找插件说明他们反汇编(而不是反编译,像jad)。



除了插件,你可能配置一个外部工具来执行

编辑:让我清楚一下上面的内容:如果你打F3,Eclipse (通常,实际过程可能略有不同):


  1. 解析目标(如果您选择的是Java文件将是Java文件本身;如果你选择或你的游标是一个类名,它将是类声明,类似于方法声明等)。

  2. 搜索构建路径(同一项目第一)为包含目标的Java文件。如果找到,则打开显示该Java源文件的可写编辑器。

  3. 对于类/方法声明,它继续在构建路径上搜索包含声明的类文件。如果找到,则



    a)如果类文件已附加了源文件,则打开链接的Java文件的只读编辑器。



    b)如果类文件没有附加到源文件,那么打开一个只读面板,显示已编译类文件的反汇编(javap-like)字节码。 / p>


我的猜测是,你认为有一个专用的键序列到3.b)认为有。但是,我再次希望在这里被证明是错误的。


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):

  1. 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).
  2. 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.
  3. 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.

这篇关于如何查看Java的字节码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆