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

前端 未结 2 1627
[愿得一人]
[愿得一人] 2020-12-21 08:51

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 Pa

相关标签:
2条回答
  • 2020-12-21 09:32

    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.

    0 讨论(0)
  • 2020-12-21 09:42

    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".

    0 讨论(0)
提交回复
热议问题