如何将原生 .so 与 Glassfish 3.1 一起使用
我正在尝试为嵌入式设备构建一个网络界面,它将显示网络统计信息。我正在使用 Glassfish 3.1 应用服务器,我想使用 jnetpcap 来监听网络流量。 jnetpcap 依赖于 libpcap 本机库。我尝试从 Oracle 查找有关在 Glassfish 中使用本机库的文档,但我还没有找到我要查找的内容(而且我可能正在寻找错误的内容)。
当我的 servlet 加载时,它失败并显示
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jnetpcap.Pcap
我将其解释为类加载器可以找到该类(我在部署时已将其指定为库)它)但无法加载它。我的第一个推断是,这可能是安全策略问题,或者 jvm 找不到 libpcap.so。
我使用 Configurations->server-config->jvm-settings 在管理控制台(即 Web 界面)中设置 system.library.path 的路径。在“路径设置”选项卡中,我将路径“/usr/bin/libpcap.so”放入本机库路径后缀字段中。当我重新启动 Glassfish 服务器时,收到以下消息:
[#|2011-03-31T13:30:13.962+1100|WARNING|glassfish3.1|null| ... GlassFishConfigBean.com.sun.enterprise.config.serverbeans.JavaConfig},原因 = JavaConfig 属性“NativeLibraryPathSuffix”从“null”更改为“/usr/bin/libpcap.so”,当 = 1301538613961|#]
时稍后在日志中,本机库路径出现在路径输出
-Djava.library.path= ... /usr/lib64:/lib64:/lib:/usr/lib:/usr/bin/libpcap.so
中,所以我认为本机库已成功加载。有没有一种方法可以检查本机库是否确实已加载?
我还禁用了安全管理器(只是暂时尝试让 servlet 工作;我计划在它工作后实施更微妙的安全策略),但这也没有解决问题。
我是否尝试正确加载本机库?如何找到有关本机库是否已加载以及为什么 org.jnetpcap.Pcap 类无法初始化的更多信息?
谢谢, 蒂姆
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,解决了。
问题是 jnetpcap 依赖于 libjnetpcap.so 而不是 libpcap.so。我的错误。
将路径正确路径 (/stuff/ ... /libjnetpcap-1.3.b4) 添加到 JVM 路径设置的本机库路径后缀字段,然后所有系统都正常运行。
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.