java.lang.UnsatisfiedLinkError no ***** .dll in java.library.path [英] java.lang.UnsatisfiedLinkError no *****.dll in java.library.path

查看:613
本文介绍了java.lang.UnsatisfiedLinkError no ***** .dll in java.library.path的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的Web应用程序中加载自定义dll文件?我尝试以下方法但失败。




  • 将所有必需的DLL复制到 system32 并尝试在 Servlet中加载其中一个Servlet 构造函数 System.loadLibrary

  • 复制所需的dll在 tomcat_home / shared / lib tomcat_home / common / lib

  • <所有这些dll都在web应用程序的 WEB-INF / lib

解决方案

为了 System.loadLibrary()可以正常工作,库(在Windows上,一个DLL)必须在 PATH 的目录位于 java.library.path 中列出的路径上系统属性(因此您可以启动Java,如 java -Djava.library.path = / path / to / dir )。



另外,对于 loadLibrary(),您可以指定库的基本名称,而不使用 .dll 结束。因此,对于 /path/to/something.dll ,您只需使用 System.loadLibrary(something)



您还需要查看您正在获得的确切的 UnsatisfiedLinkError 。如果这样说:

 线程中的异常mainjava.lang.UnsatisfiedLinkError:java.library.path中没有foo 

然后找不到 foo 库(foo.dll)在您的 PATH java.library.path 中。如果这样说:

 线程main中的异常java.lang.UnsatisfiedLinkError:com.example.program.ClassName。在这种意义上,Java不能够使用这种方法,那么这个库本身就是错误的。将您的应用程序中的本地Java函数映射到其实际的本地对等体。



首先,我将在 System.loadLibrary )调用以查看是否正确执行。如果它抛出异常或不在实际执行的代码路径中,那么您将总是得到上面解释的 UnsatisfiedLinkError 的后一种类型。



作为一个旁注,大多数人将他们的 loadLibrary()调用到类中的静态初始化程序块,使用本机方法,以确保它总是执行一次:

  class Foo {

static {
System.loadLibrary ( '富');
}

public Foo(){
}

}


How can I load a custom dll file in my web application? I tried following ways but its failing.

  • copied all required dlls in system32 folder and tried to load one of them in Servlet constructor System.loadLibrary
  • Copied required dlls in tomcat_home/shared/lib and tomcat_home/common/lib
  • all these dlls are in WEB-INF/lib of the web-application

解决方案

In order for System.loadLibrary() to work, the library (on Windows, a DLL) must be in a directory somewhere on your PATH or on a path listed in the java.library.path system property (so you can launch Java like java -Djava.library.path=/path/to/dir).

Additionally, for loadLibrary(), you specify the base name of the library, without the .dll at the end. So, for /path/to/something.dll, you would just use System.loadLibrary("something").

You also need to look at the exact UnsatisfiedLinkError that you are getting. If it says something like:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no foo in java.library.path

then it can't find the foo library (foo.dll) in your PATH or java.library.path. If it says something like:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.example.program.ClassName.foo()V

then something is wrong with the library itself in the sense that Java is not able to map a native Java function in your application to its actual native counterpart.

To start with, I would put some logging around your System.loadLibrary() call to see if that executes properly. If it throws an exception or is not in a code path that is actually executed, then you will always get the latter type of UnsatisfiedLinkError explained above.

As a sidenote, most people put their loadLibrary() calls into a static initializer block in the class with the native methods, to ensure that it is always executed exactly once:

class Foo {

    static {
        System.loadLibrary('foo');
    }

    public Foo() {
    }

}

这篇关于java.lang.UnsatisfiedLinkError no ***** .dll in java.library.path的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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