【发布时间】:2017-01-28 12:26:06
【问题描述】:
尝试在tomcat下使用netty-tcnative-boringssl-static。当从 JUnit 测试午餐代码时,它可以正常工作,但在 tomcat 容器中却不是这样。 io.netty.handler.ssl.OpenSsl 类中的这段代码正在尝试从 SSL 类的类加载器加载本机库。
private static void loadTcNative() throws Exception {
String os = normalizeOs(SystemPropertyUtil.get("os.name", ""));
String arch = normalizeArch(SystemPropertyUtil.get("os.arch", ""));
Set<String> libNames = new LinkedHashSet<String>(3);
// First, try loading the platform-specific library. Platform-specific
// libraries will be available if using a tcnative uber jar.
libNames.add("netty-tcnative-" + os + '-' + arch);
if (LINUX.equalsIgnoreCase(os)) {
// Fedora SSL lib so naming (libssl.so.10 vs libssl.so.1.0.0)..
libNames.add("netty-tcnative-" + os + '-' + arch + "-fedora");
}
// finally the default library.
libNames.add("netty-tcnative");
NativeLibraryLoader.loadFirstAvailable(SSL.class.getClassLoader(),
libNames.toArray(new String[libNames.size()]));
}
当它单独工作时(例如从 JUnit 测试),它会在 netty-tcnative-boringssl-static jar 中找到 SSL 类,并从这些 jar 依赖项中的 WEB-INF/native 中获取本机库。 但是当它在 tomcat 下运行时,它会从 tomcat 库中获取 SSL 类并且找不到本地库。
用tomcat 8和9试过
【问题讨论】: