Eclipse+maven+tomcat/jetty for remote debugging __eclipse

Source: Internet
Author: User

First, MAVEN Debug configuration, see: http://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html

Below, please see my actual operation:


first, the use of Tomcat as a container

The Tomcat container, for example, is configured in 3 different ways:

First, in the Pom.xml file of the MAVEN project, Tomcat7-maven-plugin Plug-ins should be configured below <build> <plugins>, as follows:

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!--http Port-->
<port>8080</port>
<!--application path always starts with/-->
<path>/test</path>
</configuration>
</plugin>


(1) Way one

A. Open the CMD command line and add a row of arguments before the MAVEN command executes:


Export Maven_opts=-xdebug-xnoagent-djava.compiler=none-xrunjdwp:transport=dt_socket,address=4000,server=y, Suspend=y


The above content can be found in the Bin\mavendebug.bat file of the MAVEN installation directory. (Search for Debug)


The following is a detailed explanation of the command:

-xdebug Enable debugging
-XRUNJDWP loads the JDWP JPDA reference execution instance.
Transport is used to communicate between the debugger and the processes used by the VM.
Dt_socket socket transfer.
Whether the server=y/n VM needs to be executed as a debug server.
address=8787 the port number on which the debug server listens.
suspend=y/n whether to start the VM after the debugging client establishes a connection. If set to Y, it blocks the program from running until the client connects to the corresponding listening port (here is 8787) and the program actually starts executing. We sometimes complain that the program is flashing, and that the suspend parameter can be used before the code program is executed on the local load.

Precautions:


If you are executing the jar to run the program,

-jar parameter cannot be written to the-xug parameter, debugging cannot be enabled like this:
Java-jar lib/main.jar-xdebug-xrunjdwp:transport=dt_socket,address=9527,server=y,suspend=y

To remotely debug MAVEN2-initiated programs, such as MVN Jetty:run, you can execute a command when you start a program: Export maven_opts=-xdebug-xnoagent-djava.compiler=none-xrunjdwp: Transport=dt_socket,address=4000,server=y,suspend=y "


If you are in a Windows environment, you are:


Set Maven_opts=-xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y

Executing the MVN instruction under a project managed by MAVEN will allow MVN to enter the remote debugging state, opening our configured listening port number 8787:

B. Executive command MVN Tomcat7:run, as shown in the following figure, take the Mavendebug project as an example:


Then we can use Eclipse to debug the MVN,

C. Open the IDE and configure the following:

Select the Pom.xml file for the MAVEN project you want to debug, right-click, and select "Debug as"----> "Debug configuritaions ...", pop up a window, in the left column of the window, pull down, you can see "Remote Java Application ", select it, right button," New ", the window to the right will appear some need to enter the box, according to the following figure fill in the corresponding value can be:


When the input value is complete, click the Debug button.

The command line is logged until you see the last line of the log: Starting Protocolhandler ["http-bio-8080"], and then you can use port 8080 to access your application, and 8787 ports have nothing to do with Tomcat Oh, 8080 is Tomcat's port, and 8787 is the port on which the JVM listens. In this case, the project has been started in debug mode.


(2) mode two

1. Create a MAVEN build in Eclipse's run configurations, select a good Maven project, and enter Tomcat7:run in the Goals column. Then go to "JRE" tab and enter-xdebug-xnoagent-djava.compiler=none-xrunjdwp:transport=dt_socket,address=8787 in the VM arguments column, Server=y,suspend=n


2. Open the Debug configuration, create a remote Java application, Ibid. "(1) way one of the contents of the C", so that when the server is started, you can debug remotely


(3) mode three

Add the following setting at the beginning of the tomcat/bin/Catalina.bat file:

SET Catalina_opts=-server-xdebug-xnoagent-djava.compiler=none-xrunjdwp:transport=dt_socket,server=y,suspend=n, address=8787

Then create a new remote debug in Eclipse, and the port fills in 8787.


second, take jetty as a container

1. Create a MAVEN build in Eclipse's run configurations, select a good Maven project, and enter Jetty:run in the Goals column. Then go to "JRE" tab and enter-xdebug-xnoagent-djava.compiler=none-xrunjdwp:transport=dt_socket,address=8787 in the VM arguments column, Server=y,suspend=n

2. Open Debug Configuration, create a remote Java application, enter the server address in host, generally on the native localhost. In the Port column, enter the port number 8787 in the above configuration. This way, when the server is started, you can make remote Debug. This debug approach is good outside of the jar package that can be relied on in debug and set breakpoints on it. (If you've got the source code for the jar pack)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.