Search code examples
javajconsole

How to attach JConsole to a remote JVM?


I have a Java 8 application running on a remote Linux server and need to attach a JConsole to it for debugging purposes.

From my local machine I set up a tunnel to the remote machine:

 ssh -fN -L 9999:localhost:9999 [email protected]

On the remote machine I run the application with the following system properties:

java -Dcom.sun.management.jmxremote.port=9999 \
-Dcom.sun.management.jmxremote.authenticate=false \ 
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.local.only=false \
-cp foo.jar:config com.foo.bar.Main config/blah.properties

but when I start the JConsole I get Secure connection failed.

enter image description here

If I click on "Insecure connection" I get

enter image description here

How can I get around this?


Solution

  • I managed to make it working adding an extra system property for the RMI port:

    java \
    -Dcom.sun.management.jmxremote.port=9999 \
    -Dcom.sun.management.jmxremote.rmi.port=9999 \
    -Dcom.sun.management.jmxremote.authenticate=false \ 
    -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.local.only=false \
    -cp foo.jar:config com.foo.bar.Main config/blah.properties