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

Recommended Answers

All 4 Replies

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.


in Java the JNA is the best solution for using the native code..,

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.

Try to use JNI/JNA ..,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.