We use Maven Cargo to launch our service locally and run tests on it. Here is the configuration of the plugin:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.6.8</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<zipUrlInstaller>
<url>
https://www.someurl.com/tosome.zip
</url>
</zipUrlInstaller>
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<!--<classpath>shared</classpath>-->
</dependency>
</dependencies>
</container>
<configuration>
<configfiles>
<configfile>
<file>${project.build.testOutputDirectory}/tomcat-conf/context.xml</file>
<todir>conf</todir>
<tofile>context.xml</tofile>
</configfile>
</configfiles>
<files>
<file>
<file>${project.build.testOutputDirectory}/extra-classpath</file>
<todir>shared/classes</todir>
</file>
</files>
<properties>
<cargo.start.jvmargs>
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=1099
<!-- -Xdebug-->
<!-- -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000-->
<!-- -Xnoagent-->
<!-- -Djava.compiler=NONE-->
</cargo.start.jvmargs>
<cargo.servlet.port>${maven.tomcat.port}</cargo.servlet.port>
<cargo.tomcat.ajp.port>${cargo.tomcat.ajp.port}</cargo.tomcat.ajp.port>
<cargo.rmi.port>${cargo.rmi.port}</cargo.rmi.port>
</properties>
</configuration>
<deployables>
<deployable>
<groupId>our.stuff</groupId>
<artifactId>our-artifact</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
<executions>
<execution>
<id>start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
We use the following command to launch the Cargo:
clean prepare-package cargo:run -Dcargo.tomcat.ajp.port=9080 -Dmaven.tomcat.port=8080 -Dcargo.rmi.port=9070
I've tried launching the process with both the normal IntelliJ Run button and the VisualVM Launcher one:
In both cases, the local Tomcat server launches properly and awaits requests on 8080, as usual. However, the process does not appear in the Local
list in the VisualVM application.
I tried with and without the multiple -Dcom.sun.management.jmxremote
args in the <cargo.start.jvmargs>
.
I also tried adding the connection locally by right-clicking the Local
item and selecting Add JMX Connection
and inputting the port value given to the cargo (1099
):
But nothing happens.
Precision: I'm very new to VisualVM and am not 100% certain about all this stuff. Especially selecting "JMX".
When you run your Maven
command which launches the Cargo
, you end up with two new processes. In the picture above, it's Apache Maven (pid 22512)
and Tomcat (pid 14080)
(note: PIDs are irrelevant and will most probably be different on your machine).
Since our Cargo
is configured to use Tomcat
, the Tomcat process is the one that we wanted to profile.
I had noticed and tried that before, but the VisualVM
application was very unresponsive and I thus had then started exploring other possibilities. Moreover, the second time I tried that and let the Profiler
initialize itself fully, the thing was quite unresponsive for a few minutes.