转自:http://www.wikijava.org/wiki/Debugging_a_servlet_with_tomcat_and_Eclipse_tutorial
不需要懂太多的英语,看看图就会弄了。
This tutorial will guide you through the process setting up the debugging of a simple Servlet under Eclipse using Tomcat. There are many plugins for Eclipse to help you configuring this, they all basically try to automatize the process explained in this tutorial.
It's always good to know what's going on under the hood.
The article
The configuration process for debugging a Java servlet may appear scary and complex to the beginner. However, in this tutorial I will clearly explain to you how debugging in Tomcat works as well as show you how to trigger a debugging session.
Concepts
The debugging of a web application involves several components:
The Application Server
Generally speaking all the application servers support the debug mode, you just have to enable it when starting up the application server. It will then open a debugger server (generally on port 8000). You can then connect to this port to start debugging your application. In this tutorial I will show you how to activate the debug mode in Apache Tomcat.
The IDE
You can debug your application using the default command line debugger, which will give you complete access to the debugger and to the debugged software. It is much easier though to use an IDE to support your debugging. The IDE will in this case use a TCP/IP connection to connect to the debug port (usually 8000) of the application server. In this example I will explain you how to configure Eclipse to debug your application running on Tomcat
The debugger
The debugger is an external software which allows you to debug your programs. It will be run by the application server. Most the application servers come already configured with a debugger, the one preinstalled in Tomcat is JDB.
Your code to debug
Your code will be running on Tomcat, I will not go into details on how to deploy your applications. You can debug with the method explained in this tutorial any application that runs on the application server, with no limitation whatsoever.
As you may notice the connection between the application server and the IDE uses the TCP/IP protocol, this implies that you don't need to have the tomcat running on your same machine, you don't even need to be in the same continent of it. It is enough that you have network access (ex. internet) to the server, and you can debug whatever application wherever in the world. Isn't this the coolest thing ever?
Setting tomcat in debug mode
Tomcat comes ready for debugging. To enable the debug mode you just need to write the following commands (under windows OS, analogous commands under different OSs):
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
catalina.bat jpda start
ensure to execute this from the {catalina_home}/bin directory. For simplicity I normally generate a shell script (a .bat file) to automatize the process.
I call this file debugmode.bat, it contains the three commands listed above and I normally put it in the {catalina_home}/bin directory. I am then able to start the tomcat in debug mode just by double clicking on this file with the mouse.
Deploying your application to Tomcat
In order to debug your application you must deploy it in the application server, you do this in the normal way. Nothing special about this.
Connecting Eclipse to Tomcat for debugging
To connect Eclipse to the debug server created by tomcat follow these simple steps:
- Start Eclipse
- open the project containing the servlet that you want to debug
- click on the arrow close to the debug button (the little bug) to see the drop down menu
- click on open debug dialog... (may also be labeled "Debug Configurations...")
- in the debug window double click on the Remote Java Application on the left hand side list. This will create a new debug profile.
- choose a name for the debug profile (it's just for you to easily distinguish it)
- select the project you want to debug
- verify that the other settings match your configuration
- the host is the address for your tomcat, if Tomcat is running on your machine then it will be localhost.
- the port is the one you configured in when starting Tomcat, 8000 by default
- click on debug
at this point eclipse will connect to the debug server loaded in Tomcat, so it's important to do this procedure after you load Tomcat.
You can set some breakpoints on your servlet and you will see that nothing happens. This is because the servlet is indeed NOT executed yet.
Proceeding with the debug
To execute the servlet, and start debugging your code you simply open your web browser (for example firefox) and navigate to the address of your servlet, this will execute it. The execution will block at the point you put your breakpoint and the web browser will block too, waiting for the page.
At this point you can normally debug your application as you do with other programs.
Note that your IDE is running on your machine, while the servlet is running on the application server, and so is the debugger. The two latter elements are working on the same machine, but the machine for them may be different than your local one.
Through the web browser you can call the servlet as many times as you want and your Eclipse will be showing you the details about these executions, without actually needing to click again on the debug button, this may be very handy.
Ending Debugging Session
To end a debugging session simply click the Disconnect button within the Debug perspective.
over!
- 大小: 2.3 KB
- 大小: 5.1 KB
- 大小: 4.7 KB
- 大小: 10.3 KB
分享到:
相关推荐
### 《调试的艺术:使用GDB、DDD及Eclipse》 #### 书籍概述 《调试的艺术:使用GDB、DDD及Eclipse》是一本由Norman Matloff与Peter Jay Salzman合著的专业书籍,旨在帮助程序员掌握高效调试技巧。本书不仅深入介绍...
### 调试的艺术:利用GDB、DDD和Eclipse #### 一、书籍简介 《调试的艺术》是由诺曼·马特洛夫(Norman Matloff)和彼得·杰伊·萨尔兹曼(Peter Jay Salzman)共同编著的一本专业书籍。该书由No Starch Press出版,并...
with the Invariant Sections being “Free Software” and “Free Software Needs Free Documentation”, with the Front-Cover Texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. ...
This guide takes a step-by-step approach to developing, testing, debugging, and troubleshooting JEE applications, complete with examples and tips. Table of Contents Chapter 1. Introducing JEE and ...
标题 "liferay tomcat eclipse debug" 暗示了我们正在讨论如何在Eclipse环境中调试Liferay Portal,这是一个基于Java的开源企业级内容管理和协作平台,通常与Apache Tomcat这样的Servlet容器结合使用。以下是关于这...
### 使用Eclipse构建与调试Pentaho 2.0 #### 概述 本文档将详细介绍如何在Eclipse集成开发环境中设置开发环境,包括如何连接到Pentaho Subversion仓库、检出Pentaho项目、构建这些项目以及使用独立的Java应用...
Debugging iOS Applications with IDA Pro, 最新版本,enjoy it
根据提供的信息,我们可以总结并详细解释与“debugging_with_gdb(中文版pdf)”相关的知识点。这份文档似乎是一份关于使用 GDB(GNU Debugger)进行调试的手册或指南的中文版 PDF 文件。GDB 是一个非常强大的开源调试...
《软件调试的艺术》一书,无论是中文版还是英文版,都是深入探讨调试技术的重要资源,尤其对于使用GDB、DDD和Eclipse等工具的开发者来说,更是不可或缺的参考书籍。调试是软件开发过程中的关键环节,它能帮助我们找...
### Eclipse远程调试Tomcat知识点详解 #### 一、概述 在软件开发过程中,尤其是在Web应用开发领域,远程调试是一项非常重要的技术。它可以帮助开发者在不同的环境中(如远程服务器)调试应用程序,这对于查找和...
In this tremendously revised and much longer version (in keeping with Microsoft's substantial shift to the .NET architecture), Robbins achieves great progress in making a proper professional ...
Debugging With GDB 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
然而,根据标题和描述,我们可以推断出这本书的内容涵盖使用GDB、DDD和Eclipse进行程序开发调试的方法。GDB(GNU Debugger)是一个由GNU开源组织提供的强大的命令行调试工具,DDD(Data Display Debugger)是基于GDB...
Debugging and Troubleshooting-diagnosing problems with Tomcat or a web application * * Compiling your own Tomcat, rather than using the pre-built release * * Running two or more Tomcat ...
Debugging.with.Fiddler 带书签
"Linux Debugging and Performance Tuning Tips and Techniques"这个压缩包文件显然是为了帮助用户掌握这些技能而设计的。这里,我们将深入探讨其中可能包含的一些关键知识点。 **Linux Debugging** 1. **日志分析*...
《Debugging with gdb中文带书签特别版》是一本关于GNU源代码级调试器GDB的中文教程书籍,适配gdb版本6.8.50.***。书中详细介绍了GDB的各种功能、命令以及如何使用该工具进行有效的程序调试。 首先,书中提供了一个...
Debugging Mac OSX Applications with IDA Pro, 2020最新版本,非常详细,enjoy it!