Including Native Library in Netbeans

时间秒杀一切 提交于 2019-11-27 07:54:54

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
    
vinayc

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.

Luyanda Masiko

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!