0

I want to add jni code into my servlet,i have used JNI in my desktop application but now i want to add in my java web project.
let me tell you a condition.i have logic code on c++ and i want to add that code with my java web project.so please help me out

4
Contributors
4
Replies
29
Views
3 Years
Discussion Span
Last Post by raj.mscking
0

You should be able to do it just like you did in normal JRE. You could also try compiling the C++ to a DLL and using JNA which requires a little less work than JNI.

You could also just port the C++ code to Java which might actually be faster if the C++ code is more simple than complex.

0

If you want to call C++ from Java, you'll need to use JNI - Java Native Interface.

Be warned that you lose some of the benefits of the garbage collector, since it can't deal with your C++ objects, and your code won't be portable anymore.

A Java Servlet container is definitely not the most appropriate vehicle to execute C++ code in. You could try to use JNI to make a servlet run the C++ code, but it seems to me that there are much easier and reliable ways, like good old CGI's. Tomcat can do CGI, as explained here, with some limitations and restrictions.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.