What does "Native library location" entry do in Eclipse?

12,144

Solution 1

Eclipse uses this information to build the java.library.path when it launches a Java program.

Background: Some Java frameworks depend on native code. This code usually comes in the form of a native shared library (*.so, *.dll). In Java, you can see methods with the attribute native. The code will load the shared library using System.loadLibrary().

In order to make the code independent of absolute paths, you just pass the name of the shared library to System.loadLibrary(). The System property java.library.path is then used to determine in which directories the VM should look to locate the file.

Together with Eclipse's feature to define user libraries, you can easily add Java libraries that depend on native code to your projects.

Solution 2

Are you referring to the Java Build Path configuration?

You may need this location if your project uses JNI or JNA. This directory is the location of native code (e.g. a Windows DLL written in C.)

I don't think this information is actually required until you try to run the code. You could provide this information via the Run Configuration for example.

Share:
12,144
Suzan Cioc
Author by

Suzan Cioc

Not to be offended

Updated on June 23, 2022

Comments

  • Suzan Cioc
    Suzan Cioc almost 2 years

    If adding user-defined library in Eclipse, one has an ability to set "Native library location". This field allows to enter some directory path.

    When does this path plays a part?

  • Suzan Cioc
    Suzan Cioc over 10 years
    So, there is no association between specific JAR and between it's native path? All native paths will be added to single java.library.path and will be used equivalently?
  • Suzan Cioc
    Suzan Cioc over 10 years
    P.S. Also looks like JNA ignores this path and uses other variables?
  • Aaron Digulla
    Aaron Digulla over 10 years
    While OSGi defines a way to include the DLL in the JAR, plain Java doesn't. One reason is that JNI can be used to access standard OS libraries which are installed in a fixed place. As for JNA, see the documentation how it loads shared libraries
  • Jürgen K.
    Jürgen K. over 6 years
    Just to specify the question. If you add an external jar to the Java Build Path, does the native library location always need to be set or only if the jar file is outside of the project? Or is it completely uncoupled?
  • Aaron Digulla
    Aaron Digulla over 6 years
    JAR, build path and native libraries are three things. Don't confuse them. A JAR is on the build path, so the compiler can check types. The Java compiler doesn't check DLLs (native libraries). So native libraries are irrelevant when you compile your code. At runtime, you need to add the JAR to the classpath and the DLL to the java.library.path.