Java EE 7 教程 第一部分 简介 第2章 使用教程示例 第2.9节 调试Java EE应用程序


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 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. 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. 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:

      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.

2.9 调试Java EE应用程序


2.9.1 使用服务器日志

一个可行的方法是通过查看位于 domain-dir/logs/server.log 的服务器日志得以调试应用. 此日志内包含GlassFish服务器及应用输出. 可以在任意Java类中使用 System.out.println 或 Java Logging APIs (文档规范 以及在web组件中使用ServletContext.log方法记录日志信息.

如果使用NetBeans IDE, 日志记录出现在输出窗口以及server log.

如果使用–verbose标志启动GlassFish服务器, 则所有日志和调试输出会同时出现在终端窗口或命令提示窗口和服务器日志中.如果在后台运行GlassFish服务器,则调试信息仅出现在日志中. 可以通过文本编辑器或管理控制台日志查看器查看服务器日志. 使用管理控制台日志查看器

  1. 选中GlassFish服务器节点.
  2. 单击查看日志文件.
  3. 要显示其他记录, 请按照下列步骤.
    1. 单击 修改搜索.
    2. 指定你希望看到的任何条目限制.
    3. 在日志查看器的顶部单击搜索.

2.9.2 使用调试器

GlassFish服务器支持Java平台调试架构(JPDA). 通过JPDA, 可以配置GlassFish服务器使用socket传送调试信息. 使用调试器调试应用程序

  1. 在管理控制台执行以下步骤启用GlassFish服务器调试:
    1. 展开配置节点, 然后展开服务器-配置节点.
    2. 选中 JVM设置节点. 默认调试选项为:

      正如你看到的, 默认调试器socket端口是9009. 可以更改为GlassFish服务器或其他服务未使用的端口.

    3. 选中 允许调试 复选筐.
    4. 单击 保存.
  2. 停止GlassFish服务器,然后重启它.

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.

Proudly powered by WordPress   Premium Style Theme by