---
title: "Maven - How to remote debug web application"
author: "huhu_long"
date: "2012-05-09T19:46:48Z"
tags: ["maven", "remote debug"]
categories: ["研发管理"]
slug: "maven-how-to-remote-debug-web-application"
draft: false
lastmod: "2012-05-09T19:47:57Z"
id: 1520568
url: "https://vrplat.iteye.com/blog/1520568"
---

1\. add dependence in pom.xml \[code="xml"] org.mortbay.jetty jetty 6.1.26 // not sure why failed if don't specify the version # \[/code] 2. add debugger start up class \[code="java"] 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(); } } \[/code] 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=\[b]1044\[/b],server=y,suspend=n 5. Create a new Remote Java Application in Debug Configurations use the same Port specified in MAVEN\_OPTS.