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

原文:http://docs.oracle.com/javaee/7/tutorial/doc/usingexamples009.htm
翻译:石卓林 shizhuolin@hotmail.com

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.

2.9 调试Java EE应用程序

本节将介绍如何确定是什么原因造成应用程序部署或执行错误.

2.9.1 使用服务器日志

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

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

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

2.9.1.1 使用管理控制台日志查看器

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

2.9.2 使用调试器

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

2.9.2.1 使用调试器调试应用程序

  1. 在管理控制台执行以下步骤启用GlassFish服务器调试:
    1. 展开配置节点, 然后展开服务器-配置节点.
    2. 选中 JVM设置节点. 默认调试选项为:
      -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9009

      正如你看到的, 默认调试器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 www.gopiplus.com
渝公网安渝公网安备 50010702500270号 渝ICP备09056628号-7