.dll 是否已经加载到另一个类加载器中? [英] .dll already loaded in another classloader?
问题描述
我有一个在 Tomcat 3.2.1 下运行的 web 应用程序,需要进行 JNI 调用以便访问遗留 C++ 代码中的数据和方法.加载了一个 servlet在webapp 的启动,作为其 init
方法的一部分,导致一个数据集特定于要加载到 C++ 数据中的 webapp 实例结构.
I have a webapp running under Tomcat 3.2.1 that needs to make JNI calls in
order to access data and methods in legacy C++ code. A servlet is loaded
on
startup of the webapp that, as part of its init
method, causes a data set
specific to that webapp instance to be loaded into the C++ data
structures.
此 servlet 的 Java 代码包含以下内容:
This Java code for this servlet contains the following:
static
{
try {
System.loadLibrary("JCoreImpl");
System.out.println("JCoreImpl loaded");
m_bLibraryLoaded = true;
} catch (UnsatisfiedLinkError e) {
m_bLibraryLoaded = false;
System.out.println("JCoreImpl NOT loaded " + e);
}
}
如果只有一个 web 应用程序(我们称之为webapps/aaa").
Things work fine if there is only one webapp (let's call it "webapps/aaa").
如果我有第二个与 webapps/aaa 相同的 webapp(webapps/bbb")除了 C++ 数据结构中使用的数据集,然后是 webapps/aaa启动很好,但是当 webapps/bbb 启动时我收到一个错误陈述那个:
If I have a second webapp ("webapps/bbb") that is identical to webapps/aaa except for the data set used in the C++ data structures, then webapps/aaa starts up just fine, but when webapps/bbb is started I get an error stating that:
JCoreImpl NOT loaded java.lang.UnsatisfiedLinkError: Native Library
E:WebStationinDebugJCoreImpl.dll already loaded in another classloader
我需要为每个我的本地库创建一个单独的实例webapps,因为每个实例都需要包含唯一的数据特定的网络应用程序.我已经搜索了邮件档案并阅读了Craig McLanahan 解释类加载器层次结构的电子邮件.但是我有无法找到任何特定于加载唯一实例的每个 Web 应用程序的本机库.
I need to have a separate instance of the native library for each of my webapps as each instance needs to contain data that is unique to that particular webapp. I have searched through the mail archives and read emails by Craig McLanahan explaining the classloader hierarchy. But I have not been able to find anything specific to loading a unique instance of a native library for each webapp.
推荐答案
不能两次加载同一个本机库.
You can't load the same native library twice.
将类放在<tomcat>/lib/
下的jar文件中,它将在所有战争中共享.
Put the class in a jar file under <tomcat>/lib/
, it will be shared over all wars.
这篇关于.dll 是否已经加载到另一个类加载器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!