Getting hostname with java fails in latest jdk7

前端 未结 4 1682
别那么骄傲
别那么骄傲 2021-02-14 07:43

I\'ve been getting hostname of the machine as follows:

InetAddress.getLocalHost().getHostName();

However, when I put latest JDK (jdk1.7.0_04),

4条回答
  •  独厮守ぢ
    2021-02-14 07:51

    I had the same problem and when all the following lined up it worked. host name had to be appended with DOT local

    $ scutil --get HostName
    drums
    $ scutil --get LocalHostName
    drums
    $ scutil --get ComputerName
    drums
    
    $ sudo hostname drums.local
    $ hostname
    drums.local
    
    $sudo vim /etc/hosts
    192.168.x.IP drums
    127.0.0.1 localhost drums
    255.255.255.255 broadcasthost
    ::1 localhost
    fXXX::1XXX localhost
    
    $networksetup -setv6off Ethernet
    
    $ sw_vers
    ProductName: Mac OS X
    ProductVersion: 10.9
    
    $ java -version
    java version "1.7.0_45"
    Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
    Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
    

提交回复
热议问题