Java 在eclipse中调试jar文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22636122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:59:03  来源:igfitidea点击:

Debug jar file in eclipse

javaeclipsejar

提问by user3459883

I have a jar file which is having some issue and I would like to debug it.

我有一个有问题的 jar 文件,我想调试它。

I created the application on eclipse. During dev phase I have done debug but with the source code. I wanted to debug jar file to find out the reason of error i.e. it could be source code I have is different from jar file or some jar file issue.

我在 eclipse 上创建了应用程序。在开发阶段,我已经完成了调试,但使用了源代码。我想调试 jar 文件以找出错误的原因,即它可能是我拥有的源代码与 jar 文件或某些 jar 文件问题不同。

采纳答案by rpg711

Seems like you want to remote debug.

好像你想远程调试。

The use this command to launch your jar:

使用此命令启动您的 jar:

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y -jar [JAR NAME HERE]

It should state something like :

它应该说明如下:

Listening for transport dt_socket at address : 8001

And in eclipse, create a "Remote Java Application" debug configuration. The configuration is the only thing that matters as long as you have your project of interest open. Add the project[s] of interest that you would like to debug onto your source lookup path and set the port number to the configured address from the java launch command.

在 Eclipse 中,创建一个“远程 Java 应用程序”调试配置。只要您打开感兴趣的项目,配置就是唯一重要的事情。将您想要调试的感兴趣的项目 [s] 添加到您的源查找路径中,并将端口号设置为从 java 启动命令配置的地址。

When you connect to your debug-enabled jar launch, your jar will halt execution and await debugger input upon hitting breakpoints. Just make sure you have the same version of the code in your jar and your eclipse.

当您连接到启用调试的 jar 启动时,您的 jar 将停止执行并在遇到断点时等待调试器输入。只需确保您的 jar 和 eclipse 中的代码版本相同。

回答by blackbuild

You can use a java decompiler to that effect. I suggest jd (http://jd.benow.ca/).

您可以使用 java 反编译器来实现该效果。我建议 jd ( http://jd.benow.ca/)。

However, you would also need to include a realign feature (http://mchr3k.github.io/jdeclipse-realign/) for the line numbers to match.

但是,您还需要包含重新对齐功能 ( http://mchr3k.github.io/jdeclipse-realign/) 以使行号匹配。

Of course, this can only work if debug information is included in the jar file.

当然,这只有在 jar 文件中包含调试信息时才有效。