问题解决了。libjnidiagnosticsserver.so 缺少链接器库和 libfesdiagnosticsserver.so 的路径。Java 1.4 在定位未定义符号方面必须比 Java 1.6 更加自由。感谢大家的帮助。关于公平地结束这件事的礼仪有什么建议吗?
(免责声明:Java新手)
我编写了一个 Java 应用程序,它使用 JNI 来调用我的 C++ 共享库。它打印 java 版本并在执行时获取并打印 LD_LIBRARY_PATH。
Java 1.4 版 - 一切都很好!:
/usr/bin/java -jar "javadiagnosticsserver-test.jar"
java version=1.4.2
LD_LIBRARY_PATH = /usr/lib/fesdiagnostics
Java 1.6 版 - UnsatisfiedLinkError:
“未定义符号” _ZN17DiagnosticsServerC1Ev在libfesdiagnosticsserver.so中定义。Java 1.4 看到了,Java 1.6 没有?System.loadLibrary("fesdiagnosticsserver") 调用有效。Java 1.6 loadLibrary 不知道去哪里找?
/usr/java/jdk1.6.0_26/bin/java -jar "javadiagnosticsserver-test.jar"
version=1.6.0_26
class path=javadiagnosticsserver-test.jar
os.arch=i386
sun.arch.data.model=32
$HOME = /home/esutton
$LD_LIBRARY_PATH = /usr/java/jdk1.6.0_26/jre/lib/i386/client:/usr/java/jdk1.6.0_26/jre/lib/i386:/usr/java/jdk1.6.0_26/jre/../lib/i386:/usr/lib/fesdiagnostics
Dbg: Loading native lib dependencies...
Dbg: System.loadLibrary("fesdiagnostics");
Dbg: loaded fesdiagnostics
Dbg: The undefined symbol _ZN17DiagnosticsServerC1Ev is in libfesdiagnosticsserver.so
Dbg: System.loadLibrary("fesdiagnosticsserver");
Dbg: loaded fesdiagnosticsserver
Dbg: System.loadLibrary("jnidiagnosticsserver");
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/lib/fesdiagnostics/libjnidiagnosticsserver.so: /usr/lib/fesdiagnostics/libjnidiagnosticsserver.so: undefined symbol: _ZN17DiagnosticsServerC1Ev
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1732)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at fes.JniDiagnostics.libLoad(JniDiagnostics.java:30)
at fes.JniDiagnostics.<clinit>(JniDiagnostics.java:38)
at fes.FesDiagnostics.<clinit>(FesDiagnostics.java:17)
at javadiagnosticsservertest.Main.main(Main.java:37)
两种情况下的环境是相同的:
LD_LIBRARY_PATH =/usr/lib/fesdiagnostics
PATH = /opt/ActivePython-2.7/bin:/usr/java/jdk1.6.0_26/bin: \
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin: \
/sbin:/opt/qtsdk-2010.01/qt/bin:/home/esutton/bin:/sbin: \
/opt/qtsdk-2010.01/qt/bin
JAVA_HOME = /usr/java/jdk1.6.0_26
本机 C++ 共享库编译选项:
g++ -Wl,-rpath,/opt/qtsdk-2010.01/qt/lib -shared \
-Wl,-soname,libjnidiagnosticsserver.so.1 \
-o libjnidiagnosticsserver.so.1.0.0 build/Debug/GNU-Linux-x86/ \
jnifesdiagnostics.o -L/opt/qtsdk-2010.01/qt/lib -lQtGui \
-L/opt/qtsdk-2010.01/qt/lib -L/usr/X11R6/lib -lQtCore -lpthread
ln -s libjnidiagnosticsserver.so.1.0.0 libjnidiagnosticsserver.so
ln -s libjnidiagnosticsserver.so.1.0.0 libjnidiagnosticsserver.so.1
ln -s libjnidiagnosticsserver.so.1.0.0 libjnidiagnosticsserver.so.1.0
rm -f dist/libjnidiagnosticsserver.so.1.0.0
rm -f dist/libjnidiagnosticsserver.so
rm -f dist/libjnidiagnosticsserver.so.1
rm -f dist/libjnidiagnosticsserver.so.1.0
mv -f libjnidiagnosticsserver.so.1.0.0 libjnidiagnosticsserver.so \
\libjnidiagnosticsserver.so.1 libjnidiagnosticsserver.so.1.0 dist/
当它在 Java 1.4 下工作时,我必须首先加载 jnidiagnosticsserver 的依赖项。我不明白为什么。我希望 LD_LIBRARY_PATH 会解决这个问题:
public class JniDiagnostics {
public native void open(String configurationFile);
public native void close();
public native String query(String restfulQueryString);
private static String[] libraryDependencyList = {"fesdiagnostics", "fesdiagnosticsserver", "jnidiagnosticsserver"};
private static void libLoad(String libName) {
System.out.println("Dbg: System.loadLibrary(\"" + libName + "\");");
System.loadLibrary(libName);
System.out.println("Dbg: loaded " + libName);
}
static //static initializer code
{
System.out.println("Dbg: Loading native lib dependencies...");
for (int i = 0; i < libraryDependencyList.length; i++) {
libLoad(libraryDependencyList[i]);
}
}
}
安全问题?Java版本配置问题?
提前感谢任何方向,
-埃德
CentOS 5.2 32-bit
Netbeans 6.9.1
Java version 1.6.0_26
PS:我的目标是让我的 Java 源代码在 Glassfish RESTful Web 服务中运行。如果 LD_LIBRARY_PATH 可以为 java 应用程序解决,我希望同样的解决方案将适用于 Glassfish 3。