最近在工程中用到JNotify,linux下部署的时候需要引入libjnotify.so,具体的布置可参考http://lichuanbao.iteye.com/blog/1335253.
系统启动时,一直抛出异常java.lang.NoClassDefFoundError: Could not initialize class net.contentobjects.jnotify.JNotify。localhost.*.log日志中抛出异常java.lang.UnsatisfiedLinkError: no jnotify in java.library.path
按照网上说明,配置libjnotify.so,重启;tomcat的日志中依旧抛异常信息java.lang.NoClassDefFoundError: Could not initialize class net.contentobjects.jnotify.JNotify。
确认了JNotify的jar包及libjnotify.so都已经正确的配置了,后来发现在tomcat的localhost.*.log日志中抛出异常java.lang.UnsatisfiedLinkError: /var/hmp/libjnotify/libjnotify.so: /var/hmp/libjnotify/libjnotify.so: wrong ELF class: ELFCLASS64 (P
ossible cause: architecture word width mismatch)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
原因是引入的libjnotify.so是64位系统的,而本身工程布置的linux为32位机,libjnotify.so与linux内核不符。
重新上传32位的libjnotify.so,重启,异常信息还是java.lang.NoClassDefFoundError: Could not initialize class net.contentobjects.jnotify.JNotify。而tomcat的localhost.*.log日志中抛出异常java.lang.UnsatisfiedLinkError: /usr/java/jdk1.6.0_34/jre/lib/i386/libjnotify.so: /lib/libc.so.6: version `GLIBC_2.12' not found (required by /usr/java/jdk1.6.0_34/jre/lib/i386/libjnotify.so)。
[root@localhost i386]# ldd -v libjnotify.so
ldd: warning: you do not have execution permission for `./libjnotify.so'
./libjnotify.so: /lib/libc.so.6: version `GLIBC_2.12' not found (required by ./libjnotify.so)
linux-gate.so.1 => (0x0032f000)
libc.so.6 => /lib/libc.so.6 (0x00c4c000)
/lib/ld-linux.so.2 (0x002b2000)
Version information:
./libjnotify.so:
libc.so.6 (GLIBC_2.12) => not found
libc.so.6 (GLIBC_2.1.3) => /lib/libc.so.6
libc.so.6 (GLIBC_2.0) => /lib/libc.so.6
/lib/libc.so.6:
ld-linux.so.2 (GLIBC_PRIVATE) => /lib/ld-linux.so.2
ld-linux.so.2 (GLIBC_2.3) => /lib/ld-linux.so.2
ld-linux.so.2 (GLIBC_2.1) => /lib/ld-linux.so.2
网上搜索到的解决方法有两个:
1、You can upgrade your CentOS version to 6.* to get the GCLIB_2.12 and above.
2、 you need create a libjnotify.soand remove the dependency on GCLIB_2.12
具体方法为:
cd ~/compile
mkdir jnotify
cd jnotify
unzip ~/downloads/jnotify-lib-0.94.zip
mkdir src
cd src
unzip ../jnotify-native-linux-0.94-src.zip
cd Release
export C_INCLUDE_PATH=/usr/java/jdk1.7.0_07/include/:/usr/java/jdk1.7.0_07/include/linux/
make
[root@localhost Release]# ldd -v libjnotify.so linux-gate.so.1 => (0x00d60000) libc.so.6 => /lib/libc.so.6 (0x008d7000) /lib/ld-linux.so.2 (0x002b2000) Version information: ./libjnotify.so: libc.so.6 (GLIBC_2.1.3) => /lib/libc.so.6 libc.so.6 (GLIBC_2.4) => /lib/libc.so.6 libc.so.6 (GLIBC_2.0) => /lib/libc.so.6 /lib/libc.so.6: ld-linux.so.2 (GLIBC_PRIVATE) => /lib/ld-linux.so.2 ld-linux.so.2 (GLIBC_2.3) => /lib/ld-linux.so.2 ld-linux.so.2 (GLIBC_2.1) => /lib/ld-linux.so.2
另外一种方式:可以更换适合版本的libjnotify.so (我的工程中按照上述第二种方式及更换libjnotify.so为0.93版的均实验通过)