JAVA/JNI-加载具有循环依赖项的本机DLL [英] JAVA/JNI - Load native DLL with circular dependency
问题描述
我尝试使用JNI在我的Java项目中加载c ++代码.我要加载许多DLL,但不幸的是,其中两个之间存在循环依赖关系:dll A需要dll B,而dll B又需要dll A!我知道在DLL之间具有循环依赖关系是不好的编程设计,但是在我的项目中,C ++代码对我来说是一个黑匣子.
I try to load c++ code in my java project with JNI. I have many several DLL to load, and unfortunately there is a cyclic dependency between two of them : dll A needs dll B which in turns need dll A ! I know it is a bad programming design to have circular dependencies between DLL, but in my project the c++ code is a black box to me.
有没有办法以周期性依赖方式加载DLL ?
感谢您的帮助.
jpsi
详细信息:
我的代码很简单:
System.loadLibrary("myDLLA"); // needs dll B to be loaded!
System.loadLibrary("myDLLB"); // needs dll A to be loaded!
System.loadLibrary("myDLLC"); // needs dll B
// then call my native method implemented in dll C
java库路径是可以的,并且包含两个DLL(作为VM参数给出,我也将其转储并在运行时检查了它).循环依赖性已由Dependendcy Walker确认.
The java library path is OK and contains the two DLL (it is given as VM argument, I dumped it and checked it at run time too). The cyclic dependency was confirmed by Dependendcy Walker.
错误是:
java.lang.UnsatisfiedLinkError: E:\...\myDLLA.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1928)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
我的项目是在Eclipse(Helios)中开发的,它是部署在tomcat 6服务器上的动态Web项目.
My project is developed in Eclipse (Helios) as a dynamic web project deployed on a tomcat 6 server.
请告诉我是否需要更多信息.
Please tell me if you need more information.
再次感谢您的帮助!
推荐答案
在Windows上,DLL加载程序将遵循PATH来解析外部引用.您可以将myDLLB.dll的目录全局添加到PATH(通过系统属性->高级),也可以在启动Java应用程序(set或xset)的命令行中添加,也可以从Java代码中添加.
On Windows, the DLL loader will follow the PATH to resolve external references. You can add the directory of myDLLB.dll to PATH globally (through System properties-> advanced), or on command line which launches your Java app (set or xset), or from your Java code.
这篇关于JAVA/JNI-加载具有循环依赖项的本机DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!