5

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.

6
  • The exact name of libraryname.dll is important. Commented Aug 25, 2011 at 19:11
  • Exact name? What do you mean? And how is it important? Thanks. Commented Aug 25, 2011 at 19:12
  • @Thorbjørn the exact name is not important, the path to the directory where it exists is enough Commented Aug 25, 2011 at 19:14
  • PATH and library path are two different things. Can you post some example code that exhibits the problem? Commented Aug 25, 2011 at 19:14
  • Was the original error text "The library libraryname.dll could not..."? Commented Aug 25, 2011 at 19:14

2 Answers 2

9

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

Sign up to request clarification or add additional context in comments.

3 Comments

What is the <main_class> supposed to include?
The class that contains the main() method i.e. the entry point of the program
Worked for me as jna.library.path
4

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.

4 Comments

The second option you suggested does not work for the 'java.library.path' property. See: stackoverflow.com/questions/5419039/…
Well it doesn't work all the time. But if he sets it prior to getProperty(), I think it will work. Good point that I should mention in my answer and accepting the down vote for missing that
The question is to get clarification on library.path and we should provide him the info of what is possible. I agree that it is not a good practice to set it up from the code. +1 for that comment
It is not a matter of good practice, you cannot set that specific property from code. The property is loaded as part of the JVM initialization and the value is cached; changing the property programatically will have no effect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.