How to set agentlib property for mvn tomcat plugin (jpda)
Asked Answered
Q

3

13

Related to eclipse debug remote web application => How do I debug a remote application in my eclipse

How can I set / archive this in the mvn tomcat plugin? http://tomcat.apache.org/maven-plugin-2.0-SNAPSHOT/tomcat7-maven-plugin/

The only thing that might help is setting systemProperty but that doesn't work for me ;/

Goal: let tomcat run on console via maven but enable remote debugging for different IDEs

(YES guys, we can run tomcat in Eclipse WTP! That's not the question ;)

Quits answered 14/9, 2012 at 9:51 Comment(0)
Q
30
$ export MAVEN_OPTS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
$ mvn tomcat7:run-war

^^ that's it, not cool (as it is not in POM) but it works

Source: http://aaronz-sakai.blogspot.de/2009/02/debugging-jetty-when-running-mvn.html

Quits answered 14/9, 2012 at 9:59 Comment(0)
O
6

It's a bit old thread but for the sake of completeness I though i might add a little here.

The plugin does not provide debug options configuration for whatever strange reason. Thus your only option is to manually specify debug configuration to the JVM that runs the process. In your environment, there are three ways achieve this:

  1. Using a well known-maven environment variable (as described by childno.de)
  2. Directly specifying the options to maven (no env. variable needed):

    mvn -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y tomcat7:run-war

  3. With an eclipse Run configuration That's basically the same like 2) but you define this in eclipse (that would be good if you didn't want to leave the IDE at all). To achieve that you need to specify a Maven Build Run configuration. Set the goal to tomcat7:run (or similar) and then navigate to the JRE tab. The VM arguments area is where you specify the debug configuration: -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
If you opt for 3), the precise run goal for tomcat7 is irrelevant to the debug enabling. Choose according to you use case (dynamic web project, war, etc.). Same goes for the plugin configuration. However, make sure to specify that you are using the tomcat maven plugin in the pluginManagement section of your project pom:
<pluginManagement>
   <plugins>
        <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
    </plugin>
    </plugins>
</pluginManagement>
Orang answered 24/10, 2013 at 13:6 Comment(2)
Do i have to first configure above described maven run with the JVM params, let it run and then have a second Debug configuration to remote debug? I assume if i changed the HTTP Port thats going to be teh same for the JVM arguments then?Schuss
Yes. You need to setup your remote debug client accordingly. From your question I infer it's eclipse for you, but in principle any other JPDA-capable client qualifies too. These are the default setting for eclipse remote debug configuration so it should work out of the box. If the port 8000 is not available make sure you change to another both in the server JVM debug settings (the address segment of the -Xrunjwdp option) and your client (eclipse debug config). To avoid confusion, this port is for the remote debug protocol and does not concern the HTTP/S communication with Tomcat.Orang
R
-1

OR... you could simply add the following tag to your plugin configuration

 <jpda>true</jpda>

Then when you execute: mvn tomcat7:run, it will start jpda on port 8000.

Funny thing is even though I have tested this and it works, I can't find any code in the opensource code base to explain why it works, nor have I found any way to change from the default port 8000.

Apache seems to have dropped the ball when it comes to documentation of this plugin.

Rodenticide answered 7/3, 2014 at 17:55 Comment(2)
That doesn't work for me. I'm on version 2.2 of the plugin. I also downloaded the source from Apache and ran a case-insensitive recursive grep for "jpda" and nothing was returned.Bollay
This didn't work, but adding jdpa.listen=true did. See this https://mcmap.net/q/217756/-debugging-in-mavenContemporaneous

© 2022 - 2024 — McMap. All rights reserved.