libnetty_tcnative_linux_x86_64.so: libapr-1.so.0: 无法打开共享对象文件: 没有那个文件或目录
在一个netty的项目里,使用libnetty_tcnative以及apr来使用openssl。
集成:
<project>
<properties>
<!-- Configure the os-maven-plugin extension to expand the classifier on -->
<!-- Fedora-"like" systems. -->
<os.detection.classifierWithLikes>fedora</os.detection.classifierWithLikes>
</properties>
...
<dependencies>
...
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative</artifactId>
<version>2.0.0.Final</version>
<classifier>${os.detected.classifier}</classifier>
</dependency>
...
</dependencies>
...
<build>
...
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.0.Final</version>
</extension>
</extensions>
...
</build>
...
</project>
打开日志的trace级别,发现没有连接上openssl,使用的是jdkssl。报错如下:
关键报错信息如下:
libnetty_tcnative_linux_x86_64.so: libapr-1.so.0: 无法打开共享对象文件: 没有那个文件或目录
at java.lang.ClassLoader$NativeLibrary.load(Native Method) ~[?:1.8.0_171]
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941) ~[?:1.8.0_171]
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857) ~[?:1.8.0_171]
at java.lang.Runtime.loadLibrary0(Runtime.java:870) ~[?:1.8.0_171]
at java.lang.System.loadLibrary(System.java:1122) ~[?:1.8.0_171]
at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38) ~[netty-all-4.1.29.Final.jar:4.1.29.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:336) ~[netty-all-4.1.29.Final.jar:4.1.29.Final]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_171]
原因是没有找到libapr-1.so.0,系统为Ubuntu。
解决方法:把libapr-1.so.0连接到apr的安装路径
ln -s /usr/local/apr/lib/libapr-1.so.0 libapr-1.so.0