如何在 Eclipse 中使用 javap?
正如标题所述,我尝试将 javap
与 eclipse 一起使用,但设置它时遇到困难。我尝试使用 run
菜单中的 external tools
进行设置,但找不到正确的 Arguments:
字符串以使其正常工作。基本上我需要一些能够动态执行我打开的当前文件的东西。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我使用以下外部工具配置来实现此目的:
${system_path:javap} 用于定位Eclipse使用的JDK中的javap。您可以使用 javap 的绝对路径来代替。
${project_loc}
返回项目的绝对路径。由于我找不到要使用的预定义变量,因此使用它来定位资源的.class
文件,这就是javap
在项目目录中运行的原因而不是包含.class
文件的目录。在传递给
javap
的参数中:bin
是 Eclipse 项目的默认输出文件夹。将其更改为build/classes
或项目使用的任何内容。注意,该值是相对于${project_loc}
的;您可以改为指定绝对路径。${java_type_name}
用于获取选择的类名。您可以在项目资源管理器视图或项目导航器视图中选择 Java 文件,甚至可以在任何视图中选择 Java 类型,然后运行外部工具。注意 - 当您选择方法、内部类等然后运行该工具时,这种方法效果不太好,因为它们本身不是资源,从而导致
${project_loc}将为空。
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 whyjavap
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 tobuild/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.您的问题是 javap 需要类文件的路径,但是当您选择源文件时,您可以访问 eclipse 变量
${selected_resource_loc}
包含 java 源的路径。据我了解,没有变量包含类文件的路径。我认为对您来说最简单的方法是创建接受 java 文件路径的自定义脚本,将
java
替换为class
并将源文件夹替换为 bin 文件夹。如果您使用的是 Linux,则可以使用命令sed
轻松完成。如果您在 Windows 上,可以使用命令SET
和~
来实现。请参阅帮助了解更多详细信息。祝你好运。
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
toclass
and source folder to bin folder. If you are using linux it it can be easily done using commandsed
. If you are on windows it can be implemented using commandSET
with~
. See help for more details.Good luck.
请尝试修改
工作目录
以匹配您的java项目输出文件夹。就我而言,它看起来如下所示。工作目录:
${workspace_loc:/Sample/bin}
然后我选择了
.class
文件并执行了javap
,没有任何问题。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 thejavap
without any issues.为了在 Eclipse 中反汇编当前选定的
.class
文件,我使用以下参数< /a> 在外部工具配置中。这样
bin
文件夹子包中的类也可以被反汇编。输出显示在控制台视图中。javap 参数的 Oracle 文档。
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.
除了@AlexR 建议的有价值的自定义脚本之外;另一种方法是:在 Ecplise 中打开终端窗口并使用 -p 和其他选项运行 javap 命令。
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.