Reputation: 16534
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:
spring-boot
parent.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.
Upvotes: 1
Views: 5616
Reputation: 16534
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
Upvotes: 5