Java error - cannot find library in java.library.path?

眉间皱痕 提交于 2020-01-10 05:24:06

问题


I am getting a error message like this:

The library libraryname.dll could not be loaded by Windows. Make sure that the library is in you Path environment variable. Exception in thread "main" java.lang.UnsatifiedLinkError: no libraryname in java.library.path.

This error is from me trying to run a jar file on Windows XP via cmd. I am wondering, where exactly is java.library.path? I've already added C:\Program Files\Java\jdk1.6.0_26 to my PATH but it still gives me the error. How would you go about debugging this?

Thanks.


回答1:


You can simply pass java.library.path as a system property as shown below:

java -Djava.library.path=<path_to_dll> <main_class>

First you need to find out where the libraryname.dll is and add it above in "path_to_dll".




回答2:


The error is basically saying it cannot find your native libraries. Java tries to locate your library by looking into java.library.path property

It's an System environment that you need so Java can find your native libraries when you run your application. Several ways to do it:

  • Use java -Djava.library.path=[path to your library] when running your program
  • From the code you could also do.

    
    System.setProperty( "java.library.path", "/path/to/libs" );
    
  • Set it up from your IDE. An example for Eclipse can be found in this SO question How to set java.library.path from eclipse

EDIT: A good comment below pointed out that #2 will not working 100% because you might not set this prior to calling getProperty(). Missed that point and thanks for pointing that out.



来源:https://stackoverflow.com/questions/7195778/java-error-cannot-find-library-in-java-library-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!