Fixing java.net Local host name unknown error on Mac OS X

来源:互联网 发布:造价工程师考试软件 编辑:程序博客网 时间:2024/06/08 13:23

As some of you might know, I am a big fan of modular software (functional modules). So I love OSGi. Snofyre is built on OSGi and Spring DM. Anyways, since I am in the process of rewriting Snofyre, I decided to rebase the previous OSGi code to a new OSGi framework. When doing this, I got a bizzare error at launch:

Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: MB: MB: nodename nor servname provided, or not known

For someone who’s lived in the Java world for a while, this is something I found rather strange. I did all the sanity checks on my /etc/hosts file to ensure proper entries were present but still had no luck! I even tried reseting theComputer Name from System Preferences, still no joy! And then it struck me, that Mac OS X might have got itself in a twist and I had to set the ‘HostName’ manually. Doing that using Terminal is real easy using scutil. Here is how:

scutil –set HostName “localhost”

See screenshot below, where my previous HostName was set to ‘MB‘. I changed it to ‘localhost‘ using the above command. You can use scutil –get HostName to get the current hostname.

Change Hostname using scutil

You can read more about scutil here. Remember, you need to change the hostname to something that exists in your /etc/hosts file, otherwise you might still keep getting the UnknownHostException!

1 0
原创粉丝点击