Skip to content

Instantly share code, notes, and snippets.

@m-szalik
Last active May 7, 2022 16:30
Show Gist options
  • Save m-szalik/93c559bf2ad964078e1e to your computer and use it in GitHub Desktop.
Save m-szalik/93c559bf2ad964078e1e to your computer and use it in GitHub Desktop.
How to enable remote JMX access
java -jar yourApp.jar [JVM_OPTIONS]
For local host access only JVM_OPTIONS are:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.host=127.0.0.1
-Dcom.sun.management.jmxremote.local.only=true
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
For full remote access JVM_OPTIONS are:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
Prefer IPv4 over IPv6:
-Djava.net.preferIPv4Stack=true
Example:
java -jar MyJar.jar -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.local.only=true -Dcom.sun.management.jmxremote.host=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.net.preferIPv4Stack=true
More:
http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
@meash-nrel
Copy link

may need to set "-Dcom.sun.management.jmxremote.rmi.port" as well on remote access, as RMI opens an arbitrary port unless its set (which doesn't play nice with firewall). you can set it to the same port.

@musskopf
Copy link

musskopf commented Jan 30, 2019

For remote connections you might also wanna setup the " -Djava.rmi.server.hostname=xxxxx", otherwise, it'll use the machines primary IP, which doesn't work over a tunnelled or NATed connection. Full details at: https://docs.oracle.com/javase/8/docs/technotes/guides/rmi/javarmiproperties.html

@sebastiankirsch
Copy link

sebastiankirsch commented Aug 28, 2019

For remote connections you might also wanna setup the " -Djava.rmi.server.hostname=xxxxx"

👍

@rajeshhereforyou
Copy link

Do we need to set the below property when using Java 8 ?
Dcom.sun.management.jmxremote.local.only=true

As per the below thread, it seems, this is ineffective
https://support.oracle.com/knowledge/Middleware/1641501_1.html

@hridoy100
Copy link

I've explained this in detail: Remote monitoring with visualvm and JMX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment