Forums Register Login

Java native interface under servlet

+Pie Number of slices to send: Send
I want to add jni code into my servlet,this is right way.If yes tell me a book or tutorial for basic guideline.
[ October 15, 2005: Message edited by: chandu joshi ]
+Pie Number of slices to send: Send
If you are familiar with C, then steps are quite simple:
1. create a class which should use native methods and mark some methods as native;
2. compile your class and then use javah.exe to generate C headres;
3. Implement methods in C using headers from 2;
4. add in Java code loading of .dll or .so before calling native methods
5. Note that all memory you allocated and passed to Java (for example your method returns a string) won't be collected unless you use some specific actions

I'd recommend to get JNI manual from Sun's web site, I used it and created several native implementations with great success.

As an example, you can look in SWT implementation. There is nothing specific for servlets, unless your servlet container uses security manager for limiting responsibilities of servlets. In this case you should give your servlet permission to load native libraries.

There is a small problem for serlet packaging using native method, because commonly loadlib method looks for a native library in system path. You can use load method to specify exact location of a library. I think you can figure out a location of deployed war content and provide correct path to a native library.
+Pie Number of slices to send: Send
 

Originally posted by chandu joshi:
[QB]I want to add jni code into my servlet,this is right way.If yes tell me a book or tutorial for basic guideline.



By the way, why you want to do this?
I would say you should not, otherwise your application would be no more platform independent.
Happily living in the valley of the dried frogs with a few tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1052 times.
Similar Threads
Is there any way to get Servlet Init Parameter using EL?
javascript, servlets and SVG
Export in Excel
Capturing Form Data
How can I change the sdk version of Websphere 4 if I already install it
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:21:08.