55

I am running a Java application on Java 6 VM on a remote Windows XP, on which I can run jvisualvm.exe to connect to the running application automatically.

Now I need to connect that application from my local computer, but I don't know the JMX port number of the remote computer. Where can I find it? Or, must I restart that application with some VM parameters to specify the port number?

After reading the question How to find the JMX port in a server, I executed the command on the remote computer

netstat -apn

but got nothing.

Community
  • 1
  • 1
chance
  • 5,735
  • 11
  • 39
  • 68
  • possible duplicate of [How to activate JMX on my JVM for access with jconsole?](http://stackoverflow.com/questions/856881/how-to-activate-jmx-on-my-jvm-for-access-with-jconsole) – artbristol Apr 26 '12 at 11:05

1 Answers1

75

Now I need to connect that application from my local computer, but I don't know the JMX port number of the remote computer. Where can I find it? Or, must I restart that application with some VM parameters to specify the port number?

By default JMX does not publish on a port unless you specify the arguments from this page: How to activate JMX...

-Dcom.sun.management.jmxremote # no longer required for JDK6
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.local.only=false # careful with security implications
-Dcom.sun.management.jmxremote.authenticate=false # careful with security implications

If you are running you should be able to access any of those system properties to see if they have been set:

if (System.getProperty("com.sun.management.jmxremote") == null) {
    System.out.println("JMX remote is disabled");
} else [
    String portString = System.getProperty("com.sun.management.jmxremote.port");
    if (portString != null) {
        System.out.println("JMX running on port "
            + Integer.parseInt(portString));
    }
}

Depending on how the server is connected, you might also have to specify the following parameter. As part of the initial JMX connection, jconsole connects up to the RMI port to determine which port the JMX server is running on. When you initially start up a JMX enabled application, it looks its own hostname to determine what address to return in that initial RMI transaction. If your hostname is not in /etc/hosts or if it is set to an incorrect interface address then you can override it with the following:

-Djava.rmi.server.hostname=<IP address>

As an aside, my SimpleJMX package allows you to define both the JMX server and the RMI port or set them both to the same port. The above port defined with com.sun.management.jmxremote.port is actually the RMI port. This tells the client what port the JMX server is running on.

rogerdpack
  • 50,731
  • 31
  • 212
  • 332
Gray
  • 108,756
  • 21
  • 270
  • 333
  • 6
    You missed `-Dcom.sun.management.jmxremote.ssl=false` and `-Djava.rmi.server.hostname=` – Claudio Aug 02 '16 at 07:08
  • Neither of those are required @Claudio up to Java 7 at least. – Gray Aug 02 '16 at 15:12
  • 2
    Not in my experience. I'm running Java 7 on Linux CentOS 6 . I found your answer, and it didn't work. Fortunately, you also provided the link to the original answer and adding those flags it started working.No idea which one was actually needed and why. – Claudio Aug 02 '16 at 15:59
  • If you are using Wildfly, please consult; https://docs.jboss.org/author/display/WFLY10/JMX+subsystem+configuration – Koekiebox May 20 '17 at 08:48