简体   繁体   中英

Stack trace in eclipse

How to trace stack through eclipse? In my code I am trying to upload a file, when I execute file uploading action in the application, it just hangs with no error messages. I have tried debugging, but it hasn't helped much.

Assuming that you are running the application from Eclipse, but inside a Java EE container like Glassfish or Tomcat, invoking the printStackTrace() method on an exception object (when caught) will display the stack trace in the console window in Eclipse. In your case, you would first need to know if an exception is being thrown at all. I would not recommend creating an Exception object at runtime only to deduce the stacktrace from it.

This is of course, not a good practice when writing production quality code, and you should look at using a logging framework like log4j, jul or slf4j to trace the application behavior.

If push comes to shove, enable debugging of the servlet container (this varies from container to container), so that you can trace the behavior of the container itself in addition to your application.

  • On the server start "jvisualvm" in the JDK bin folder as the same user as started Glassfish.
  • Attach to the Glassfish process by double clicking the appropriate entry under "Local".
  • On the Threads panel click the Thread Dump button.
  • Copy the stack trace to the clipboard.
  • In Eclipse, paste the stack trace in the Java Stack Trace Console View in the Console panel.

I'd recommend stepping through with the eclipse debugger to find out where it hangs. This will automatically give you a stack trace as you step through.

I find the "step into" (F5) feature most useful, this lets you recursively descend into functions to explore what is happening.

You can set breakpoints at the beginning of your file upload code so that you can start stepping through at approximately the right place. In my version of Eclipse the stack trace appears in the top left "Debug" pane underneath the appropriate thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM