我在运行java程序时遇到问题,该程序将InetAddress.getLocalHost作为非root用户调用 在特定的linux rhel机器上。 我尝试在没有任何问题的情况下在另一台机器上运行该程序(无论是root用户还是非root用户)。
错误:
at java.net.UnknownHostException: thebox: thebox: Temporary failure in name resolution
at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
代码:
public class MyInetAddress {
public static void main(String[] args) throws UnknownHostException {
InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
}
}
环境:
# java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (rhel-2.4.7.1.el6_5-x86_64 u55-b13)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
# uname -rmo
2.6.32-279.2.1.el6.x86_64 x86_64 GNU/Linux