How to use javap with eclipse?

孤街浪徒 提交于 2020-01-10 07:19:34

问题


As the title states, I'm trying to use javap with eclipse but have difficulties setting it up. I'm trying to set it up using external tools from the run menu but can't find the correct Arguments: string to make it work. Basically I need something that will dynamically execute the current file I have opened.


回答1:


I use the following external tool configuration to achieve this:

${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.




回答2:


Your problem is that javap requres path to class file but when you select your source file you can access eclipse variable ${selected_resource_loc} contains path to java source. As far as I understand there is no variable that contains path to class file.

I think that the easiest way for you is creating your custom script that accepts path to java file, replaces java to class and source folder to bin folder. If you are using linux it it can be easily done using command sed. If you are on windows it can be implemented using command SET with ~. See help for more details.

Good luck.




回答3:


Please try by modify the Working Directory to match your java project output folder. In my case, it looks as given below.

Working Directory: ${workspace_loc:/Sample/bin}

Then I selected the .class file and executed the javap without any issues.




回答4:


In order to disassemble the currently selected .class file in Eclipse I use the following arguments in the External Tools Configurations.

This way classes in subpackages of the bin folder can also be disassembled. The output is displayed in the Console view.

Oracle documentation of javap parameters.




回答5:


In-addition to the valuable custom script suggested by @AlexR; the other way is : Open the terminal windows within the Ecplise and run the javap command with -p and other option.



来源:https://stackoverflow.com/questions/7056987/how-to-use-javap-with-eclipse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!