eclipse Java 代码不同步时如何调试?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12539649/
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-09-19 19:01:46  来源:igfitidea点击:

How to debug Java code when it is out of sync?

javaeclipse

提问by Grothaar

One of the problems I'm running into is that my jar files and my source files don't match.

我遇到的问题之一是我的 jar 文件和我的源文件不匹配。

I'd like to:

我想:

  1. Be Notified when when source and binary don't match (I think Visual Studio can do something like this...)
  2. Set break points not by line, but by function. For example, set a break point at the entry of function foo().
  1. 当源代码和二进制文件不匹配时收到通知(我认为 Visual Studio 可以做这样的事情......)
  2. 不是按行设置断点,而是按功能设置断点。例如,在函数 foo() 的入口处设置一个断点。

I use eclipse mainly; so Solutions for eclipse would be most appreciated, but any IDE (or command line debugger) will do. Thanks!

我主要使用eclipse;所以 eclipse 的解决方案将是最受赞赏的,但任何 IDE(或命令行调试器)都可以。谢谢!

回答by Frankie

When developing just use and link to .classfiles that are saved by your IDE.

开发时只需使用并链接到.classIDE 保存的文件。

If your project starts to grow to a point where it's really useful to link to a .jaryou're better off treating the jar's as separate projects.

如果您的项目开始增长到链接到一个非常有用的地步,.jar您最好将 jar 视为单独的项目。

回答by Bananeweizen

Use method breakpointsinstead of line breakpoints. They can be set to halt on entering/exiting a method. You get them by double clicking the left editor side in a line containing a method declaration.

使用方法断点而不是行断点。它们可以设置为在进入/退出方法时暂停。您可以通过双击包含方法声明的行中的左侧编辑器侧来获取它们。

回答by Saurabh Mathur

Go to Project tab in Eclipse and then

转到 Eclipse 中的 Project 选项卡,然后

  • click clean: Project->Clean…
  • click build automatically: Project->Build automatically
  • 点击清理:项目->清理...
  • 点击自动构建:项目->自动构建

回答by Kevin Day

The debug information is limited to line numbers in the source file... I do agree that having a warning that the lines are wrong would be nice, but that would require more meta data in the jar than I think is available...

调试信息仅限于源文件中的行号......我同意警告行错误会很好,但这将需要 jar 中的元数据比我认为可用的更多......

You might want to consider addressing the challenge with a change in your build process. This isn't exactly answering your question, but hopefully it will give you a strategy that will address the underlying problem.

您可能需要考虑通过更改构建过程来应对挑战。这并不能完全回答您的问题,但希望它可以为您提供解决潜在问题的策略。

When you generate the jar for deployment, also generate a jar with the binary AND source. For investigating the source code of a stack trace on the live server, set up a separate project in eclipse and have the binary+source jar be on the classpath. You may have to explicitly set the source code location back to the same jar (though I think Eclipse will just do this automatically).

生成用于部署的 jar 时,还要生成一个带有二进制 AND 源的 jar。要在实时服务器上调查堆栈跟踪的源代码,请在 eclipse 中设置一个单独的项目,并将二进制 + 源 jar 放在类路径上。您可能必须将源代码位置显式设置回同一个 jar(尽管我认为 Eclipse 会自动执行此操作)。

Then you just have to add copying of the binary+source jar into the appropriate location in your workspace as you do your deployments (preferably with a deployment script).

然后,您只需在进行部署时将二进制+源 jar 的副本添加到工作区中的适当位置(最好使用部署脚本)。

If it's your server, you may want to even consider deploying the binary+source jar to the live server - that way you will always be able to get at the source.

如果它是您的服务器,您甚至可能需要考虑将二进制+源代码 jar 部署到实时服务器 - 这样您将始终能够获得源代码。