开发者

How to view Java's byte code in eclipse IDE?

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. 开发者_JAVA百科

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.


Using the following external tool configuration we can view java byte code in eclipse with the help of javap:

How to view Java's byte code in eclipse IDE?

To get the above pop-up select Run option and select External Tools and select External Tools configuration...

How to view Java's byte code in eclipse IDE?

${system_path:javap} is used to locate javap in the JDK used by the Eclipse. You can use an absolute path to javap instead.

${project_loc} returns the absolute path to the project. This is used, since I could not find a pre-define variable to use, to locate the .class file of a resource, and that's why javap runs in the project's directory instead of the directory containing the .class file.

Among the arguments passed to javap:

  • bin is the default output folder for Eclipse projects. Change this to build/classes or whatever is used by the project. Note, the value is relative to ${project_loc}; you can specify absolute paths instead.
  • ${java_type_name} is used to obtain the selected class name.

You can select a Java file in the Project explorer view or Project navigator view, or even a Java type in any of the views, and then run the external tool. Note - this approach doesn't work quite well when you select a method, an inner class etc. and then run the tool, as they are not resources on their own, leading to the scenario where ${project_loc} will be empty.

Source


Dr. Garbage Tools is a suite of Eclipse Plugins released under Apache Open Source license.

Install Bytecode Visualizer using Eclipse Marketplace.

To view a bytecode:

  1. Right click on .java file, select open with and select other you will get the following popup:

    How to view Java's byte code in eclipse IDE?

  2. Search "Bytecode Visualizer" and select the option it opens the file as follows there you can find Bytecode option as shown:

    How to view Java's byte code in eclipse IDE?


Enhanced Class Decompiler

"Window > Preferences > General > Editors > File Associations"

Change default to your for both .class association.

"*.class" : "Class Decompiler Viewer" is selected by default.

"*.class without source" : "Class Decompiler Viewer" is selected by default.

How to view Java's byte code in eclipse IDE?


You can use ASM 4.0 Plugin.

How to view Java's byte code in eclipse IDE?

Installation

The Bytecode Outline plugin can be installed from the Eclipse Update Manager with the ObjectWeb Eclipse Update Site http://download.forge.objectweb.org/eclipse-update/ Alternatively, the plugin can be downloaded from the ObjectWeb Forge site, and manually installed in the Eclipse plugins directory.

Usage

To see the bytecode of the current .java or .class file:

Window -> Show View -> Other -> Java -> Bytecode

To compare the bytecode of two .java or .class files:

select two *.class or *.java files -> right click -> Compare with -> Each Other Bytecode

or

select one *.class or *.java file -> right click -> Compare with -> Another Class Bytecode

http://asm.ow2.org/eclipse/index.html


Well... if the .class is selected in the Navigator View or Package Explorer view, a simple F3 is enough to open a decompiled version of it in the editor.

How to view Java's byte code in eclipse IDE?


As hinted at by user833970: The Bytecode Outline plugin: http://andrei.gmxhome.de/bytecode/index.html

At its base, it provides a "bytecode" view for the currently opened Java file which is what you were looking for.

However, you can also assign it to load any random .class file instead of the default .class viewer, and it surpasses it in many ways. For example, this viewer actually jumps to the right spot in the bytecode if you click on a member in the Outline view.

Download links (for dropin use) can be found at the afore-mentioned link, the update-site is http://andrei.gmxhome.de/eclipse/.


If you are really interested in the bytecode there is a eclipse plugin that lets you open and edit the bytecode of a .class file using a text editor.

https://github.com/itemis/jbc

How to view Java's byte code in eclipse IDE?


I've tried several different solutions for this. Bytecode Visualizer (available here: https://sourceforge.net/projects/drgarbagetools/ ) is, in my opinion, the best solution. It neatly displays the output and makes clear how it links to the source code. I've noticed a few minor misinterpretations on some of the bytecodes, but you can get the gist of it.

Unfortunately, it doesn't seem to support Neon at time of writing. It does support Mars, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜