Maven - How to remote debug web application


1. add dependence in pom.xml
		<dependency>
			<groupId>org.mortbay.jetty</groupId>
			<artifactId>jetty</artifactId>
			<version>6.1.26</version> // not sure why failed if don't specify the version #
		</dependency>


2. add debugger start up class
package debugger;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;

public class JettyWebStarter {
	public static void main(String[] args) throws Exception {
		Server server = new Server();

		SelectChannelConnector connector = new SelectChannelConnector();
		connector.setPort(80); // change this port number if it is taken by other program
		server.addConnector(connector);

		WebAppContext context = new WebAppContext();

		context.setContextPath("/");
		context.setDescriptor("src/main/webapp/WEB-INF/web.xml");
		context.setResourceBase("src/main/webapp");

		server.setHandler(context);

		server.start();
	}

}


3. mvn clean install

4. debug this class and you are able to debug the code now.

-------------------- or you can -----------------
4. Create a new Program in External Tools Configuration
Location: C:\JSpace\Software\apache-maven-3.0.4\bin\mvn.bat
Working Directory: ${workspace_loc:/petstore-web}
Arguments: jetty:run
!!! NOTE, go to Environment Tab !!!
please make sure your environment variables are set correctly.
MAVEN_OPTS: -Xdebug -Xrunjdwp:transport=dt_socket,address= 1044,server=y,suspend=n

5. Create a new Remote Java Application in Debug Configurations
use the same Port specified in MAVEN_OPTS.

猜你喜欢

转载自vrplat.iteye.com/blog/1520568
今日推荐