即使在 LD_LIBRARY_PATH 中明确声明了 libmysqlclient.so.18 时,尝试执行我的Java应用程序也会产生UnsatisfiedLinkError
异常。 >, -Djava.library.path 和 /etc/ld.so.conf
我正在尝试使用libcap的Java包装器pcap4j(https://github.com/kaitoy/pcap4j),以便可以从Java应用程序嗅探计算机NIF上的数据包。 由于libpcap需要超级用户特权才能执行此任务,因此我必须以某种方式赋予执行此应用程序的非特权用户访问NIF的能力。
pcap4j的维护者建议向Java命令授予功能CAP_NET_RAW
和CAP_NET_ADMIN
,如下所示:
setcap cap_net_raw,cap_net_admin=eip /path/to/java
由于实施方面的限制,我受到如下约束:
在向Java命令授予CAP_NET_RAW
和CAP_NET_ADMIN
能力之后,出现了问题。执行我的应用程序时出现以下异常:
Error creating entity
java.lang.UnsatisfiedLinkError: /path/to/app/lib/libxpherejava.so: libmysqlclient.so.18: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
JAVA: java-1.8.0-openjdk-1.8.0.171-8
操作系统: Linux user-me 3.10.0-862.6.3.el7.x86_64#1 SMP Fri Jun 15 17:57:37 EDT 2018 x86_64 x86_64 x86_64 GNU / Linux [Red Hat Enterprise Linux Server版本7.5(Maipo)]
LD_LIBRARY_PATH 包含未找到库的显式路径:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/lwp:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre/lib/amd64/jli/libjli.so:/usr/lib64/mysql/libmysqlclient.so.18
export LD_LIBRARY_PATH
通过使用 java.library.path ,将LD_LIBRARY_PATH传递给JVM:
exec java
-XshowSettings:properties
-Djava.library.path=${LD_LIBRARY_PATH}
-d64
...
执行Java命令时,“-XshowSettings:properties” 为我提供以下输出:
java.library.path =
/path/to/app/lib
/path/to/app/lib/glib-2.0
/usr/lib/lwp
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre/lib/amd64/jli/libjli.so
/usr/lib64/mysql/libmysqlclient.so.18
其中/usr/lib64/mysql/libmysqlclient.so.18
是指向/usr/lib64/mysql/libmysqlclient.so.18.0.0
的符号链接
似乎像JVM(或任何请求从 libxpherejava.so 访问 libmysqlclient.so.18 的实体)找不到 libmysqlclient.so.18 < / em>,即使其路径已明确提供给 java.library.path和文件确实存在。
在LD_LIBRARY_PATH包含libmysqlclient.so.18(/usr/lib64/mysql/libmysqlclient.so.18)的路径的情况下,发出 libxpherejava.so的ldd 将产生libmysqlclient.so.18可以找不到
[user@user-me log]$ ldd /path/to/app/lib/libxpherejava.so
linux-vdso.so.1 => (0x00007ffe1a73d000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007fd727df4000)
libssl.so.10 => /lib64/libssl.so.10 (0x00007fd727b83000)
libxphereS.so => /path/to/app/lib/libxphereS.so (0x00007fd727973000)
libmysqlclient.so.18 => not found
libz.so.1 => /lib64/libz.so.1 (0x00007fd72775d000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fd727543000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd727327000)
libm.so.6 => /lib64/libm.so.6 (0x00007fd727025000)
libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007fd726d11000)
libc.so.6 => /lib64/libc.so.6 (0x00007fd726944000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fd726740000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fd7264f3000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fd72620b000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fd726007000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007fd725dd4000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd728718000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fd725b72000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fd725964000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fd725760000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fd725547000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fd725320000)
这是 ld.so.conf 的内容:
[user@user-me lib]$ cat /etc/ld.so.conf
/path/to/app/lib/
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre/lib/amd64/jli/libjli.so
/usr/lib64/mysql/libmysqlclient.so.18
两个库都是64位编译的:
[user@user-me lib]$ file libxpherejava.so
libxpherejava.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=82e1c673e732eb2d3770883b14facf3eff091243, not stripped
[user@user-me lib]$ file /usr/lib64/mysql/libmysqlclient.so.18
/usr/lib64/mysql/libmysqlclient.so.18: symbolic link to libmysqlclient.so.18.0.0'
[user@user-me lib]$ file /usr/lib64/mysql/libmysqlclient.so.18.0.0
/usr/lib64/mysql/libmysqlclient.so.18.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=79978c5f4fb259a5a146614e260ea0720dd31d3b, stripped
执行“ exec java”命令的脚本上的 strace 会产生--https://dumpz.org/aGHQpNk9Znmk
有人知道为什么找不到 libmysqlclient.so.18 吗?
答案 0 :(得分:0)
在libmysqlclient.so.18
下创建到有问题的库/usr/lib64
的符号链接可以解决该问题。例外不见了。