what code gets executed
I have some J2EE application, and I'm able to see the what that application is doing in it's web interface. I also have the source code for the application. I want to realize what code is actually executed, when I click something in the web interface.
What is the best method to find out this? I was 开发者_JAVA技巧thinking of putting the breakpoint on the first line of each method, but it is quite annoying to do it manually :-), so I hope that is some better method. Thanks for answering.Your application is deployed on an application server. You can debug it by starting the server in debugging mode. JBoss for example has a nice tool suite for eclipse. With the tools, debugging is just a press of a button away (the one with the bug).
Logging is definitely an option too, though you will not get as much detail. Personally I prefer logback over commons for a number of reasons.
If you have no clue, where to set your breakpoints/ where to log, and the package structure is not helpful, you could start with methods in your EJBs. Look for annotations like @Stateless
, @EJB
(to find injection points and go from there) for example.
If there are servlet classes, start there, or if it is a JSF frontend, look for @ManagedBean
annotations.
Adding log messages to your APIs is the best and recommended way out to figure out the control flow (and also has been one of the most powerful mechanisms of debugging historically).
If you wish, you could have most of them at DEBUG
level, so as to switch them on/off from a development to production-like environment (where you would most likely not need it).
I think apache logger is a great way to track the flow.. cos its all self written. eclipse provides a log viewer plugin through which u can view it.. however when it comes to web applications, i think monitoing is also crucial.. using jconsole u can have a look at the threads being executed.. and using jmap u can find out the classes and the objects loaded... i am not aware if the output is in the order that they are loaded.. if so .. then u can get a good idea of how the classes are loaded .. and the instances consumed by each one of them.
How about adding a Servlet Filter that only justs passes everything through to the chain and putting your breakpoint there?
Be sure to have the proper filter mapping in your web.xml and your breakpoint should be in the way of all matching URL's.
add a logger. you can also use logger libraries, for example Apache Commons Logging.
精彩评论