zno2

Remote Debugging (3)

use Eclipse| a Web application

创建一个简单的web项目

AServlet.java

package cn.zno;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        response.getWriter().append("Served at: ").append(request.getContextPath());
        
    }

}
AServlet.java

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
      <servlet-name>AServlet</servlet-name>
      <display-name>AServlet</display-name>
      <description></description>
      <servlet-class>cn.zno.AServlet</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>AServlet</servlet-name>
      <url-pattern>/AServlet</url-pattern>
  </servlet-mapping>
</web-app>
web.xml

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>cn.zno</groupId>
    <artifactId>za</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>za Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provider</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>za</finalName>
    </build>
</project>
pom.xml

构建一个war

[INFO] Building war: F:\e\workspacetest\za\target\za.war

部署到远程tomcat并以debug模式启动

%CATALINA_HOME%/webapps/

webapps
│   host-manager
│   manager
│   ROOT
│   za.war

设置debug模式的参数(通过setenv.bat设置)

%CATALINA_HOME%/bin/  下添加文件 setenv.bat 内容如下

set "JAVA_OPTS= -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=y %JAVA_OPTS%"

如下图:

该文件会自动被catalina.bat 执行

启动

F:\e\tomcat\apache-tomcat-7.0.70\bin>startup.bat

 会出现挂起的tomcat

 

启动debugger

 

远程电脑tomcat会继续执行,将 za 部署,日志如下:

Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/7.0.70
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Jun 15 2016 16:27:45 UTC
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         7.0.70.0
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 7
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            6.1
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             F:\e\java\jdk1.8.0_101\jre
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_101-b13
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         F:\e\tomcat\apache-tomcat-7.0.70
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         F:\e\tomcat\apache-tomcat-7.0.70
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Xdebug
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=y
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.util.logging.config.file=F:\e\tomcat\apache-tomcat-7.0.70\conf\logging.properties
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=F:\e\tomcat\apache-tomcat-7.0.70\endorsed
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=F:\e\tomcat\apache-tomcat-7.0.70
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=F:\e\tomcat\apache-tomcat-7.0.70
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.io.tmpdir=F:\e\tomcat\apache-tomcat-7.0.70\temp
Sep 20, 2016 12:18:23 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: F:\e\java\jdk1.8.0_101\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;F:\e\java\jdk1.8.0_101\bin;C:\Program Files\TortoiseSVN\bin;E:\apache-ant-1.9.6\bin;C:\Program Files\Git\cmd;F:\e\maven\apache-maven-3.2.5\bin;.
Sep 20, 2016 12:18:23 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Sep 20, 2016 12:18:23 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 838 ms
Sep 20, 2016 12:18:23 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 20, 2016 12:18:23 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.70
Sep 20, 2016 12:18:23 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive F:\e\tomcat\apache-tomcat-7.0.70\webapps\za.war
Sep 20, 2016 12:18:24 PM org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
INFO: validateJarFile(F:\e\tomcat\apache-tomcat-7.0.70\webapps\za\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Sep 20, 2016 12:18:24 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive F:\e\tomcat\apache-tomcat-7.0.70\webapps\za.war has finished in 551 ms
Sep 20, 2016 12:18:24 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory F:\e\tomcat\apache-tomcat-7.0.70\webapps\host-manager
Sep 20, 2016 12:18:24 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory F:\e\tomcat\apache-tomcat-7.0.70\webapps\host-manager has finished in 127 ms
Sep 20, 2016 12:18:24 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory F:\e\tomcat\apache-tomcat-7.0.70\webapps\manager
Sep 20, 2016 12:18:24 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory F:\e\tomcat\apache-tomcat-7.0.70\webapps\manager has finished in 92 ms
Sep 20, 2016 12:18:24 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory F:\e\tomcat\apache-tomcat-7.0.70\webapps\ROOT
Sep 20, 2016 12:18:24 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory F:\e\tomcat\apache-tomcat-7.0.70\webapps\ROOT has finished in 79 ms
Sep 20, 2016 12:18:24 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Sep 20, 2016 12:18:24 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 20, 2016 12:18:24 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 977 ms

 

访问浏览器

http://localhost:8080/za/AServlet

即可进入到AServlet中的断点

浏览器页面加载中且进入到了Eclipse中的断点

 

继续执行后,浏览器显示结果

 

posted on 2016-09-20 17:15  zno2  阅读(184)  评论(0编辑  收藏  举报

导航