Including Native Library in Netbeans

After struggling with this for a while, I've found a working solution to the problem.

I used System.out.println(System.getProperty("java.library.path")); within my code to find out what the actual value for java.library.path was on my system. It's at least a concatenation of the %PATH% variable for the system and user environment variables. So all I needed to the was add the location of my libraries to either of those and the problem went away.


You can also load the library from within the program using this line:

System.loadLibrary("jmtp")

Place the folder containing the file jmtp.dll directly under the Java project.

Alternatively, I tried this and it works:

System.setProperty( "java.library.path", "libs" );

Whereas "libs" is the folder that contained the dll and is placed directly under the java project folder.

I noticed that the jmtp.dll gives the following exception with a 64-bit JDK:

Exception in thread "main" java.lang.UnsatisfiedLinkError: libs/jmtp (.\libs/jmtp.dll is not a valid Win32 application. )
    at java.lang.ClassLoader.loadLibraryWithPath(ClassLoader.java:1018)
    at java.lang.ClassLoader.loadLibraryWithClassLoader(ClassLoader.java:982)
    at java.lang.System.loadLibrary(System.java:506)
    at podcasts.Transferer.main(Transferer.java:28)

You will need to run the program on a 32-bit JDK for this to work.


Finally i found the solution, In order to include native library we need to add following steps in netbeans

     ==>Right click on the Project
     ==>Properties
     ==>Click on RUN
     ==>VM Options : -Djava.library.path="C:\Your Directory where Dll is present"
     ==>Ok