The Java EE 7 Tutorial

Previous
Next

2.9 Debugging Java EE Applications

This section explains how to determine what is causing an error in your application deployment or execution.

2.9.1 Using the Server Log

One way to debug applications is to look at the server log in domain-dir/logs/server.log. The log contains output from GlassFish Server and your applications. You can log messages from any Java class in your application with System.out.println and the Java Logging APIs (documented at http://docs.oracle.com/javase/7/docs/technotes/guides/logging/index.html) and from web components with the ServletContext.log method.

If you use NetBeans IDE, logging output appears in the Output window as well as the server log.

If you start GlassFish Server with the --verbose flag, all logging and debugging output will appear on the terminal window or command prompt and the server log. If you start GlassFish Server in the background, debugging information is available only in the log. You can view the server log with a text editor or with the Administration Console log viewer.

2.9.1.1 To Use the Administration Console Log Viewer

  1. Select the GlassFish Server node.

  2. Click View Log Files.

    The log viewer opens and displays the last 40 entries.

  3. To display other entries, follow these steps.

    1. Click Modify Search.

    2. Specify any constraints on the entries you want to see.

    3. Click Search at the top of the log viewer.

2.9.2 Using a Debugger

GlassFish Server supports the Java Platform Debugger Architecture (JPDA). With JPDA, you can configure GlassFish Server to communicate debugging information using a socket.

2.9.2.1 To Debug an Application Using a Debugger

  1. Follow these steps to enable debugging in GlassFish Server using the Administration Console:

    1. Expand the Configurations node, then expand the server-config node.

    2. Select the JVM Settings node. The default debug options are set to:

      -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9009
      

      As you can see, the default debugger socket port is 9009. You can change it to a port not in use by GlassFish Server or another service.

    3. Select the Debug Enabled check box.

    4. Click Save.

  2. Stop GlassFish Server and then restart it.

Previous
Next