在Ubuntu上的Tomcat中加载共享本机库 [英] Loading a shared native library in Tomcat on Ubuntu

查看:201
本文介绍了在Ubuntu上的Tomcat中加载共享本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Ubuntu上的Tomcat6中加载共享库?

How do I load a shared library in Tomcat6, on Ubuntu?

我创建了一个名为libawragrids.so的库awragrids并将其放入

I have created a library "awragrids" with name "libawragrids.so" and placed it in

/var/lib/tomcat6/shared

我在终端设置了以下环境变量,我称之为启动tomcat:

I have set the following environment variables in the terminal from which I call start tomcat:

export PATH=$PATH:/var/lib/tomcat6/shared
export JAVA_OPTS="-Djava.library.path=/var/lib/tomcat6/shared"
export LD_LIBRARY_PATH=/var/lib/tomcat6/shared

然后尝试使用

private static final String GRIDTOOL_LIBRARY_NAME = "awratools";

static {
    try {
        System.loadLibrary(GRIDTOOL_LIBRARY_NAME);
    } catch (java.lang.SecurityException e) {
        System.out.println("Not allowed to load dynamic library " + GRIDTOOL_LIBRARY_NAME + ".");
        throw e;
    } catch (java.lang.UnsatisfiedLinkError e) {
        System.out.println("Failed to load dynamic library " + GRIDTOOL_LIBRARY_NAME + ".");
        throw e;
    }
}

并在第二个区块结束。我所做的所有阅读都表明,前两个出口中的任何一个都应该成功。在Windows上,我将awragrids.dll放在路径上的一个文件夹中,它运行正常。

and wind up in the second catch block. All the reading I've done suggests that either of the first two exports should do the trick. On windows, I put "awragrids.dll" in a folder on the path and it works fine.

我花了很多时间方式在这个,真的需要睡一觉......请帮忙!

I have spent way too much time on this and really need to get some sleep... please help!

推荐答案

我认为这可能是我的错误部分。当我最初编译库时,它有一个不同的名称(libawargrids.so),因此我将其重命名为:

I think this may have been a mistake on my part. When I originally compiled the library, it had a different name ("libawargrids.so"), so I renamed it with:

mv libawragrids.so libawratools.so

虽然等效似乎适用于Windows,但也许并非如此在Linux上工作。当我使用名称awratools再次编译它(生成libawratools.so)时,问题消失了。

While the equivalent seems to work on Windows, perhaps it doesn't work on Linux. When I compiled it again using the name "awratools" (producing "libawratools.so), the problem went away.

虽然问题现在已经解决,但如果有人可以确认如果重命名可能是导致它的原因(也许可以解释为什么),那将不胜感激。

While the problem is now fixed, if someone could confirm that the renaming is probably what caused it (and perhaps explain why), that would be appreciated.

对于浪费人们的时间感到抱歉,但感谢您的帮助!

Sorry for wasting peoples time but thanks for the help!

PS我现在已下线:

export JAVA_OPTS="-Djava.library.path=/var/lib/tomcat7/shared"
export LD_LIBRARY_PATH=/var/lib/tomcat7/shared

位于/etc/init.d/tomcat6的顶部,因此无论哪个用户启动该服务都无关紧要。如果出于某种原因,请告知我这是不是很糟糕。

at the top of /etc/init.d/tomcat6, so it does not matter which user starts the service. Please let me know if this is, for some reason, bad.

这篇关于在Ubuntu上的Tomcat中加载共享本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆