1

I'm want to enable JMX for my spring boot application and tried everything but without success. I think, the problem is, that I'm using the repackage option of the spring-boot-maven-plugin.

At the moment I did the following:

export JAVA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1617 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1"
java -jar target/myapp-1.0.0.jar

But when I start the application, it does not listen on port 1617. I cannot connect from a JMX client and ss -tulpen also does not list the port.

I also tried it by passing the -D... parameters directly. I also tried it with --com.sun... and thought Spring boot could handle them this way. I also tried many other things on multiple machines, without success.

Some further information:

  • My application does not use any spring-boot parent.
  • I'm trying this on an ArchLinux system.
  • I don't have any special iptables configuration, all ports should be available on the configured ip.
  • Spring boot version: 1.4.1.RELEASE
  • Java version: openjdk version "1.8.0_112"

What am I doing wrong and where can I find a documentation with help on that?

UPDATE: I added some lines for reading and printing the passed JAVA_OPTS (as explained here). When I start the application through IntelliJ and setting the VM options to the JAVA_OPTS value from above, it works. The passed options are printed and the VM is listening on port 1617. When I start the application using java -jar my.jar -Dcom.sun.... the parameters are not printed and the VM is still not listening on port 1617.

Community
  • 1
  • 1
Ethan Leroy
  • 15,804
  • 9
  • 41
  • 63

1 Answers1

5

Problem solved! I still don't know why it does not work with JAVA_OPTS but I know what I did wrong when passing the options directly: It seems that I always passed the -jar ... option before the -Dcom.sun... options. But what I found out now:

The order of these options is essential!

What? Really?

Yes!

So, the way that works for me now:

java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1617 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar my.jar

and this one does not work:

java -jar my.jar -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1617 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
Ethan Leroy
  • 15,804
  • 9
  • 41
  • 63
  • 1
    Thank you very much! I was looking for this whole day! – Sasa May 02 '17 at 17:10
  • 2
    This is because you are running a jar: everything after `-jar my.jar` is passed as arguments to your main method (`String[] args`), not as JVM options. – Bastien Jansen Sep 15 '18 at 13:54