26

I am sure I can figure it out if I can see the JAVA OPTS parameters. I want to monitor a hornetq server using Jconsole, so I need the port number.

I remember using some command like java grep etc when I connected to it a while back.

Clebert Suconic
  • 5,353
  • 2
  • 22
  • 35

4 Answers4

32

If you know the process number you can use netstat to find what ports the program is listening on with something like

$ netstat -apn | grep <proc num>

The conventional port for JMX listeners is 1099.

matt b
  • 138,234
  • 66
  • 282
  • 345
14

I know it's an old post. You can also get the details from System:

String jmx1 = System.getProperty("com.sun.management.jmxremote");
String jmx2 = System.getProperty("com.sun.management.jmxremote.port");
String jmx3 = System.getProperty("com.sun.management.jmxremote.authenticate");
String jmx4 = System.getProperty("com.sun.management.jmxremote.ssl");
String jmx5 = System.getProperty("java.rmi.server.hostname");
Gray
  • 115,027
  • 24
  • 293
  • 354
Tristan Everitt
  • 457
  • 6
  • 6
4

You can also manually set the port from the JVM commandline settings, e.g:

-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=1616
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
Gray
  • 115,027
  • 24
  • 293
  • 354
Steve Smith
  • 388
  • 4
  • 8
2

You can programmatically access the JVM arguments like so:

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
...       
RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = RuntimemxBean.getInputArguments();
Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710