java.library.path is a System property, which is
used by Java programming language, mostly JVM, to search native libraries,
required by project. Similar to PATH and Classpath environment
variable, java.library.path also includes a list of
directory. When Java code loads a native library (a library or executable
written in language like C, C++ or native code) using System.loadLibrary("name
of library") method, java.library.path is scanned
for specified library. If JVM doesn't found requested native library, then it
throw java.lang.UnsatisfiedLinkError: no native
library in java.library.path. Now some one may argue that, why does
Java program should depend on native library, doesn't this make a Java
application platform dependent? Well, he would be right, but there are
situations, where most of code is already written in native languages, and you
are just writing some Java code on top of that. In those scenario, instead of
rewriting whole stuff, you tend to use native libraries. Sometimes a third party JAR (written in
Java) depends upon some native components as well. If you have been using Tibco
RV messaging, then you might know that Java API for Tibco RV depends upon several
dll files, and until those files are present in java.library.path, you can
not run those Java program successfully. Since most of us, run Java program
from Eclipse IDE, it's important to know How to set java.library.path in
Eclipse. In this Java tutorial, I will show you couple of ways to set java.library.path in Eclipse
IDE, you can follow similar steps in other IDE like Netbeans or IntelliJ to set
java.library.path
3 Ways to set java.library.path in Eclipse IDE

1) You can set java.library.path in Eclipse by providing native
library location for you libraries inside "java build path". Just
follow below steps :
1.1) Select Project
==> Properties ==> Java Build Path ==> Libraries ==> JRE System
Library ==> Native library location ==> Edit
1.2) Edit will open a
dialog box, which allows you to choose an external folder, or a workspace location,
to find native libraries
2) Similar to above steps, you can also set native library location,
which will then converted into java.library.path by Eclipse, into source tab.
Each source folder allows you to specify a native library location.
1.1) Open Java Build Path as
shown in above step, then choose Source tab
1.2) Each Source folder has
one native library location, select and edit them to include your native
libraries
3) Third way to set java.library.path is by using VM arguments. Open Run
Configurations or Debug Configuration of your project and provide -Djava.library.path="native
library path" in Arguments tab, under VM arguments.
So, you can see It's not difficult to set java.library.path in Eclipse.
It's also worth noting that, this system property is only read, when JVM startup. IF you further
change this System property using System.setProperty("java.library.path",
"new path"), it won't take into effect.
No comments:
Post a Comment