I\'m trying to connect jconsole to a jvm invoked by:
java \\
-Djava.util.logging.config.file=./logging.properties \\
-Dcom.sun.management.jmxremote.ssl=false \\
new and better solution than using a manually coded agent, is to use the new parameter which seems to be introduced in Java 7:
-Dcom.sun.management.jmxremote.rmi.port=7091
So in combination - same port can be used:
-Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.rmi.port=7091
Solution found here: http://hirt.se/blog/?p=289
make sure you run your application using below command,
java -Dcom.sun.management.jmxremote.port=9595 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -jar <your jar file name>
then open jconsole with admin privilege; you might be able to connect without any issue.
if you want to run multiple jar files, make sure to use different ports; otherwise it will give error saying it's already bind by the JVM
You can set the second port with parameter -"Dcom.sun.management.jmxremote.rmi.port" where port number can be same as that of first one . Even after setting this it will promt for insecure connection ... please allow insecure connection then only it will allow you to proceed further otherwise till then in log you will find error failed to connect: java.lang.SecurityException: Expecting a sun.rmi.server.UnicastRef2 remote reference in stub!
Thanks
The out-of-the-box JMX implementation uses two ports - one for the registry (the one that you specified) and one for the actual connection which is selected randomly (!). This is quite a design flaw since the random selection of the second port makes it very hard to configure a firewall.
There are ways around it however - either you can do it yourself manually, or if you are using Tomcat you let it handle it for you.