Using Java 7, I can launch a JVM with JMX enabled without any problems using these properties:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=8787
If I use Java 8 (Java build 1.8.0_45-b14; Java HotSpot(TM) 64-Bit Server VM build 25.45-b02, mixed mode), I always get an error like this:
java.net.MalformedURLException: Local host name unknown:
java.net.UnknownHostException: 185-69-214-74.ded.intelignet.com.br:
185-69-214-74.ded.intelignet.com.br: unknown error
The error also happens if I add this system property:
-Djava.rmi.server.hostname=185.69.214.74
However, I can successfully launch Java 8 if I don't enable JMX.
Why don't I see the same problem under Java 7? What is causing this and what should I do to avoid this error even with JMX enabled?
More details:
$ hostname
mybox
$ hostname -i
185.69.214.74
$ host $(hostname -i)
74.214.69.185.in-addr.arpa domain name pointer 185-69-214-74.ded.intelignet.com.br.
A possible work-around is to edit /etc/hosts to add this line:
185.69.214.74 185-69-214-74.ded.intelignet.com.br
However, I'm not allowed to do this, so I must find another way to solve this problem.
Best Answer
After debugging class
java.net.InetAddress
, methodgetLocalHost
, I've seen it callsInet4AddressImpl.getLocalHostName
, which returns "185-69-214-74.ded.intelignet.com.br" when I use '-Djava.net.preferIPv4Stack=true'. If I omit 'java.net.preferIPv4Stack', thenInetAddress.getLocalHost
callsInet6AddressImpl.getLocalHostName
, which returns "mybox" and the problem goes away.In other words, 'UnknownHostException' only happens if these conditions are both true:
So I'll just omit
-Djava.net.preferIPv4Stack=true
, since I haven't figured out another way of fixing this.