Adding the agent#
Add -javaagent to the JVM that runs your code. Where it goes depends on how that JVM starts.
Where to put -javaagent#
| Runner | Where | Example |
|---|---|---|
Fat jar, or plain java |
JAVA_TOOL_OPTIONS |
spring-batch |
| Spring Boot | JAVA_TOOL_OPTIONS |
spring-boot-mvc |
| Helidon SE | JAVA_TOOL_OPTIONS |
helidon-se |
| Quarkus | JAVA_TOOL_OPTIONS |
quarkus |
| Micronaut | JAVA_TOOL_OPTIONS |
micronaut |
| Maven Surefire | argLine |
junit-maven |
| Gradle | tasks.test.jvmArgs |
junit-gradle |
| Tomcat | CATALINA_OPTS |
tomcat-war |
| Jetty | JAVA_OPTIONS |
jetty-war |
| WildFly | JAVA_OPTS |
wildfly-war |
| Open Liberty | jvm.options |
open-liberty-war |
JAVA_TOOL_OPTIONS applies to every JVM started with it, build tools included. Set it only for
the application.
JMX flags#
To record with JDK Mission Control, add these flags in the same place.
-Dcom.sun.management.jmxremote.port=7091
-Dcom.sun.management.jmxremote.rmi.port=7091
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=localhost
Warning
Anyone who can reach this port can control the JVM, with no password. Use these flags only on your development machine.
From a container or another host#
- Container: publish the port to your machine only, as in
-p 127.0.0.1:7091:7091. Keepjava.rmi.server.hostname=localhost. - Another host: set
java.rmi.server.hostnameto the name JDK Mission Control uses for that host, and connect to<host>:7091. Use a network you trust.
JDK Mission Control connects to the port, then to the host named in java.rmi.server.hostname, so
both must be reachable.