Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local debugging application launched on tomcat with cargo in IntelliJ

I am trying to enable debugging in my cargo configuration. I'm using cargo-maven2-plugin version 1.4.19 with the following configuration.

<plugins>
  <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.4.19</version>
    <configuration>
      <container>
        <containerId>tomcat8x</containerId>
      </container>
      <configuration>
        <type>standalone</type>
        <properties>
        <cargo.servlet.port>8080</cargo.servlet.port>
        <cargo.jvmargs>
          -Xmx2048m
          -Xms512m
          -Xdebug
          -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=63342
          -Xnoagent
          -Djava.compiler=NONE
        </cargo.jvmargs>
      </properties>
    </configuration>
    <deployer>
    </deployer>
    <deployables>
      <deployable type="war" file="target/spa.war"></deployable>
      </deployables>
    </configuration>
  </plugin>

The application launches with this configuration but IntelliJ never connects to the JVM to enable debuging. How can I make IntelliJ connect to the JVM?

like image 459
Pablo Jomer Avatar asked Apr 06 '16 08:04

Pablo Jomer


People also ask

How to enable remote debugging in IntelliJ IDEA for Tomcat?

Note the “address=9999” means the network port number used by Tomcat for debugging. Second, open IntelliJ IDEA community edition, go to “Run -> Edit Configurations”, click the “+” icon and select “Remote” from the list, then you will see a dialog like below:

How to change the port for Tomcat in IntelliJ?

That way when you start the configuration, Intellij will connect via Socket to the Tomcat server that emits via port 8000. You can change the port for Tomcat, to something else, in the Tomcat server.xml file, in the config folder. Once the Tomcat server is started you can run this configuration.

How do I debug a Tomcat application?

Run/Debug Configurations Tab: Server: Application Server: Type "Tomcat 8.5.38" Open browser -> URL -> http://localhost:8080/ Tomcat Server Settings -> Type -> Same File System -> Host -> Same File System Remote Connection Settings -> Host -> localhost -> Port -> 8080 Startup/Connection Tab Run -> No specific parameters needed. Debug ...

Is it possible to debug Tomcat web apps in idea Community Edition?

Even though IntelliJ functionality to debug tomcat web apps available in IntelliJ Ultimate Edition, there is no such option to be seen in the community edition. I will guide you to do this task in IDEA Community Edition in a Linux environment. First, you need to set up a port for the debugger to attach itself to your running version of tomcat.


2 Answers

I fixed this like this.

<plugins>
  <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.4.19</version>
    <configuration>
      <container>
        <containerId>tomcat8x</containerId>
      </container>
      <configuration>
        <type>standalone</type>
        <properties>
        <cargo.servlet.port>8080</cargo.servlet.port>
        <cargo.jvmargs>
          -Xmx2048m
          -Xms512m
          -Xdebug
          -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009
          -Xnoagent
          -Djava.compiler=NONE
        </cargo.jvmargs>
      </properties>
    </configuration>
    <deployer>
    </deployer>
    <deployables>
      <deployable type="war" file="target/spa.war"></deployable>
      </deployables>
    </configuration>
  </plugin>

I used another port by changing the address like so.

-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009

I then created an IntelliJ run config for a remote by going to. Run > Edit Configurations > + > Remote I configured the remote to go to localhost and the port I had previously chosen <9009>.

enter image description here

After doing this I can start the cargo run and then start the debugger as a separate process to enable bugging.

If you want you can change the suspend argument to no like so.

-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9009

Then the cargo build will start without running the debugger.

like image 79
Pablo Jomer Avatar answered Sep 23 '22 09:09

Pablo Jomer


For gradle 4.3.0, under the json path cargo>local add the below param,

jvmArgs = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000

and to start the app use,

./gradlew cargoRunLocal

like image 41
Kannan Ramamoorthy Avatar answered Sep 19 '22 09:09

Kannan Ramamoorthy