Tuesday, August 25, 2009

Adding dll Files to Eclipse Projects

I had a project where I was using a dll file and Java JNI for generating some alert sounds based on some events in my java code. After developing in pain text java files for some time, I planned to move it to Eclipse IDE, to speed up my development. But where to place my dll file.

(dll files contain the implementation of the native method implementations for some java Native method calls. Hence they are like Library file, in other words, Native Libraries)

Issue here was that, dll files are searched for not in the CLASSPATH but in PATH. Where to place that the file gets to be in the path of the Project builder and also during runtime. (I was missing the ease of placing it in the invocation/current directory when I was working without the IDE)

Well finally got the link to add Path to native libraries to the project. Navigate to Project-->Properties-->Java Build Path-->Libraries Tab. Now expand JRE system Library. You can see an entry for "Native Library location". Click on the same and then on "Edit". Specify the path of the folder which contains your dll file and you are done.

But wait, this does not make your project portable. What if you want it to be part of the project and be bundled with the same. It should be placed some where within the project folder. This is what precisely i did.

Placed it in src folder of the project root folder. Modified the Native library location to point to Workspace\Project-folder\src. Done. Now application is portable along with the dll.

A picture of the option pane to guide you better:


Happy Native Coding :-)

3 comments:

  1. The Emperor Casino: The Home of Online Casino Gaming
    The Emperor Casino has over 250 online casino games. The 제왕카지노 Best Live Casino matchpoint Games. Play on our games 10bet anywhere. No Download & No Registration Needed!

    ReplyDelete