How to debug Java code when it is out of sync?
One of the problems I'm running into is that my jar files and my source files don't match.
I'd like to:
- Be Notified when when source and binary don't match (I think Visual Studio can do something like this...)
- Set break points not by line, but by function. For example, set a break point at the entry of function foo().
I use eclipse mainly; so Solutions for eclipse would be most appreciated, but any IDE (or command line debugger) will do. Thanks!
When developing just use and link to .class files that are saved by your IDE.
If your project starts to grow to a point where it's really useful to link to a .jar you're better off treating the jar's as separate projects.
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...
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).
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).
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.
Use method breakpoints instead 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.