To load a native library in java you can use one of these approaches:
Using System.load
You can use System.load(String filename)
function to load a library directly from the file system, you must specify the absolute path name of your native library. For example System.load("/System/libraries/libSomeNative.dylib")
.
Using System.loadLibrary
You can alternatively use System.loadLibrary(String libName)
function to load a native library. This method is system dependent and require that
you specify java.library.path
with the paths where your native library is located. In your case you can use -Djava.library.path=/path/toNativeLib/
as a java argument.
Alternatively since you're trying with Eclipse you can specify also this path in the follow way: Right click on project > Properties. Then select Java Build path and click on Source tab, here if you expand your source folder you can set the Native library location specifying the path of your native library:

Since this call is system dependent note that libName
parameter of the System.loadLibrary(String libName)
is not the native library name directly. In MAC OS X (it works diferent on others OS) it use the lib
prefix and the .dylib
suffix on the libName
, so to specify libSomeNative.dylib
you've to use SomeNative
as libName
.
Summarize, for example to load /System/libraries/libSomeNative.dylib
you've to specify java.library.path=/System/libraries/
as explained above and make a call to System.loadLibrary("SomeNative")
.