我正在尝试在 Ubuntu 8u131-b11-0ubuntu1.17.04.1
上使用 log4j
2.8 运行 slf4j
。当通过 Maven 运行简单的 Java 类时,openjdk 无法解析本地主机名:
Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: preferIPv6Address
at java.base/java.net.InetAddress.init(Native Method)
at java.base/java.net.InetAddress.init(Native Method)
at java.base/java.net.InetAddress.<clinit>(InetAddress.java:333)
at org.apache.logging.log4j.core.util.NetUtils.getLocalHostname(NetUtils.java:53)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:539)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:122)
at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
似乎这个方法
public static InetAddress getLocalHost() throws UnknownHostException
在Oracle Java中,实现方式与其他Java版本不同。
/etc/hosts
包含IPv6记录:
::1 ip6-localhost ip6-loopback