tags:

views:

29

answers:

3

i have a web based j2ee application. is there any way to use .dll file in it.

A: 

Yes, you can just use JNI / System#loadLibrary() the same way as you would do in a normal Java application. You only need to realize that this runs at the server side, not at the client side. If your intent is to run this at the client side, then you need to serve it in flavor of an applet or webstart application.

BalusC
A: 

First, your application server has to be capable of loading native libraries from its application class loaders in order for System#loadLibrary to work; in other words, it must implement ClassLoader#findLibrary. Otherwise, you must use System#load and somehow know the absolute path to your dll.

Second, placing native libraries in a J2EE application will affect the ability to restart the application because JNI restricts the ability of multiple class loaders to load the same native library. If the application class loader from the first instance of the application is not garbage collected before attempting to restart the application (either because of a leak or because GC is not predictable), then second instance of the application will likely not work when it fails to load the native library. For that reason, I recommend that native libraries and the classes that use them be placed in a server-wide class loader, or at least one that is guaranteed never to reloaded.

bkail
A: 

What you need is something called Java Native Interface .

A very easy article to guide you through it is JNI Basics - 1 . A more in depth "article" (or better book) is The JavaTM Native Interface Programmer's Guide and Specification . Another good tutorial is available from IBM developerworks: Java programming with JNI (you have to register but it's for free and worthwhile).

harigm