Sometime java needs to talk to native library i.e. dll or system lib. But how java going to load this native library?Adding this native lib in classpath will do ?
Java provides a way to load these native libraries by providing a property called java.library.path. This property is part of system environment.
Enough for talk. Let's get into action.
How to load these special native libraries? Java says do it through a special way by calling System.loadLibrary() ,If JVM doesn't find these libraries ,
it will throw UnsatisfiedLinkError.
How to set java.library.path? There are multiple ways to do it.
1) Through Java coding
System.setProperty("java.library.path","/path/to/library/dll")
2)Through command line
java -Djava.library.path=<path_to_dll> <main_class>
Or it can be done by setting VM property
-Djava.library.path="<path_to_dll>"
Happily Done ...
No comments:
Post a Comment