I am trying to build a web interface for an embedded device, that will display network statistics. I am using Glassfish 3.1 Application Server, and I would like to use jnetpcap to listen to network traffic. jnetpcap relies on the libpcap native libraries. I have tried to find documentation from Oracle about using native libraries with Glassfish, but I haven't found what I am looking for yet (and I may be looking for the wrong thing).
When my servlet loads it fails with
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jnetpcap.Pcap
which I interpret to mean, that the class loader can find the class (I have specified it as a library when I deploy it) but cannot load it. My first inferences were that it might have been a security policy problem, or that the jvm couldn't find the libpcap.so.
I set the path for system.library.path in the admin console (ie the web interface) using Configurations->server-config->jvm-settings. In the 'Path Settings' tab, I put the path '/usr/bin/libpcap.so' in the Native Library Path Suffix field. When I restarted the Glassfish server, I got the following message:
[#|2011-03-31T13:30:13.962+1100|WARNING|glassfish3.1|null| ... GlassFishConfigBean.com.sun.enterprise.config.serverbeans.JavaConfig}, reason = JavaConfig attribute 'NativeLibraryPathSuffix' was changed from 'null' to '/usr/bin/libpcap.so', when = 1301538613961|#]
and later in the logs the native library path turns up in the path output
-Djava.library.path= ... /usr/lib64:/lib64:/lib:/usr/lib:/usr/bin/libpcap.so
so I think the native library is being successfully loaded. Is there a way that I can check that native library is indeed loaded?
I have also disabled the security manager (just for the time being, to try to get the servlet to work; I plan to implement more subtle security policies once it's working), and that hasn't fixed the problem either.
Am I trying to load the native library correctly? How can I find out more information about whether the native library is loaded, and about why the org.jnetpcap.Pcap class cannot be initialized?
Thanks, Tim
Okay, solved.
Problem was jnetpcap depends on libjnetpcap.so not libpcap.so. My mistake.
Added the path correct path (/stuff/ ... /libjnetpcap-1.3.b4) to the Native Library Path Suffix field of the JVM Path Settings, and it was all systems go.