现情况如下:
我现在又一个DLL,我想用java的JNI或者jacob调用里面的方法,假设现在这个DLL文件名叫TESTDLL.dll,里面有两个函数:第一个是method1,里面传两个参数是字符串型的,这个函数返回一个数字。
        第二个方法是method2,里面传两个参数,一个是数字,一个是字符串,这个函数返回空。
现在我已经在静态方法里加载了,可是报错,报没有依赖类库,求指点!
static{
   System.loadLibary("TESTDLL");
}下面就不会写了。。也求指点!希望大家不吝指教

解决方案 »

  1.   

    推荐使用JNA去调用DLL,JNA对JNI进行了封装,使用起来更方便简单,也是跨平台的。
      

  2.   

    必须让动态链接器能找到这个TESTDLL.dll才行,要将此dll的路径加入到动态链接器的库路径,否则你随便搞个System.loadLibary去加载,系统怎么找到这个dll?
      

  3.   

    我只知道Linux下设置动态链接库路径的方法,windows没接触过,你自己上网搜索一下应该可以找到的。
    JNI加载库的原理是解释程序利用dlopen接口(或者与其类似的接口)动态链接和加载so/dll,并调用其中的方法.dlopen的描述信息:dlopen()
           The function dlopen() loads the dynamic library file named by the null-
           terminated  string  filename  and  returns  an  opaque "handle" for the
           dynamic library.  If filename is NULL, then the returned handle is  for
           the  main  program.   If  filename  contains  a slash ("/"), then it is
           interpreted as a  (relative  or  absolute)  pathname.   Otherwise,  the
           dynamic  linker  searches  for the library as follows (see ld.so(8) for
           further details):       o   (ELF only) If the executable file for the calling program  contains
               a  DT_RPATH  tag,  and  does not contain a DT_RUNPATH tag, then the
               directories listed in the DT_RPATH tag are searched.       o   If, at the time that the program was started, the environment vari‐
               able  LD_LIBRARY_PATH was defined to contain a colon-separated list
               of directories, then these are searched.  (As  a  security  measure
               this  variable  is  ignored  for  set-user-ID and set-group-ID pro‐
               grams.)       o   (ELF only) If the executable file for the calling program  contains
               a  DT_RUNPATH  tag,  then  the  directories  listed in that tag are
               searched.       o   The cache file  /etc/ld.so.cache  (maintained  by  ldconfig(8))  is
               checked to see whether it contains an entry for filename.       o   The directories /lib and /usr/lib are searched (in that order).       If  the  library has dependencies on other shared libraries, then these
           are also automatically loaded by the  dynamic  linker  using  the  same
           rules.  (This process may occur recursively, if those libraries in turn
           have dependencies, and so on.)
      

  4.   

    报没有依赖类库应该是你这个TESTDLL.dll执行过程中会依赖到的其它类库(比如dll)不存在吧?
    能看到具体是什么类库吗,知道的话,就把缺失的放入系统的类库路径比如System32中
      

  5.   

    前两天刚做过JNI的。此问题原因可能是你加载的dll中有引用其它Dll。加载Dll时,需先加载被引用的Dll。
      

  6.   

     System.loadLibrary("TESTDLL");  /* dll文件放在C:\WINDOWS\system32下面,执行此语句 */
    //System.load("E:\\TESTDLL.dll");    /* 文件放在任意目录下,括号内为dll的路径,dll名需要加上.dll */是不是因为你的dll文件的路径不对?