JMX agent throws java.net.MalformedURLException when host name is set to all numeric value
Asked Answered
S

5

17

We are using tomcat 7.0.27 in our application. We are below setting jmx properties on tomcat startup.

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8666 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

If the centOS server hostname on which this tomcat is running is set to all numeric value like 005056940096, tomcat does not start. It gives below exception.

Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: 005056940096: 005056940096 Server is running on centOS6. If hostname is set to non numeric value, it works properly.

I tried setting hostname in /etc/hosts and /etc/sysconfig/network, it still does not work. I also tried setting below property to server ip address, still it does not work. -Djava.rmi.server.hostname=${IP}

Please let me know if you have come across any such issue. Thanks.

Sassaby answered 20/11, 2013 at 10:50 Comment(0)
O
29

I had also the same problem, but I found out:
The reason is that tomcat tries to bind to an IP so it does not use localhost, but your hostname.
In my case: SUSEDesktop. So I had to add a hosts entry to /etc/hosts:

127.0.0.1    SUSEDesktop
::1          SUSEDesktop

Replace SUSEDesktop with the host name of your computer, you can find it out with: uname -n

Orontes answered 17/11, 2014 at 19:37 Comment(2)
This answer worked for me! In my case, I only experienced the problem when on my home network. At work, the DNS server could resolve my hostname so Tomcat ran just fine. At home, the DNS server couldn't resolve my hostname, thus making the HOSTS file entry necessary.Cryolite
As I am using the office system, so somehow the uname got changed. Adding entry of the same to the hosts file fixed the issue for me. ThanksHooey
L
19

echo "127.0.0.1 $HOSTNAME" | sudo tee -a /etc/hosts

Lent answered 18/9, 2015 at 13:18 Comment(0)
M
5

I had the same problem, finally solved by adding "Local" or "local" to /etc/hosts Something like 127.0.0.1 localhost Local local

Mop answered 29/4, 2014 at 20:27 Comment(0)
V
5

I had a similar problem starting a Spring-Boot app from the Spring Tools Suite on a Mac. It was a download from a Spring MVC / Spring Boot example for SOLR off Github.

The error was something like: java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException:XXXXXXX-221227.this.that.foo.other

By adding these two lines to the /private/etc/hosts file on my Mac the problem went away. No "re-up" of the network interfaces was necessary.

127.0.0.1       XXXXXXX-221227.this.that.foo.other

::1             XXXXXXX-221227.this.that.foo.other

I assume this was related to the above issue with tomcat and a numeric name... as my computer name (supplied by the corporation) had numbers in it.

In any case, as soon as I could ping XXXXXXX-221227.this.that.foo.other (obviously now the same as pinging localhost or 127.0.0.1) the spring boot app started (From the Spring Tools Suite UI) with no problem.

Oddly, the spring boot app started FINE from the command line with:

 mvn spring-boot:run 

-- I have no idea what the difference is/was.

Vickers answered 8/10, 2015 at 16:50 Comment(1)
I had trouble starting Tomcat after upgrading to macOS Sierra 10.12. This solved my problem. Thank you.Antonyantonym
S
0

Same issue faced following update to the hostname via CLI that was not reflected in to /etc/hosts. Resolved by replacing old hostname in /etc/hosts with sed:

sed -i 's/<old_name>/<new_name>/' /etc/host
Steersman answered 17/6, 2019 at 15:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.