Calling C++ method from JSP

I need to call a C++ method from a JSP. I hope to use JNI but everything I read says I need to compile my Java code with the -jni extenstion to create the C++ header. How do I do this with a JSP since the JSP is compiled at runtime? Do I need to call an external Java function?

Any help would be appecitated.

Thanks

[341 byte] By [dan_k13] at [2007-9-26 3:24:20]
# 1

Hi!

Its the class that contains the native method that's needed to be compiled with the -jni option. It's not the JSP class that is required to compile with the -jni option.

Let's say that you have a C++ class called MyClass that you want to access. You could then have a Java class called JMyClass with a lot of native methods. You compile it the usual way and one time with the -jni option. After that you must do some "glue code", ie implement the functions that are declared in the header file. When developing your JSP classes, all you have to do is to put the JMyClass in your classpath.

So my suggestion is that you have Java wrapper classes for each C++ class that you want to use. Thus, your JSP classes contains no native methods at all.

Regards

Johan

joka at 2007-6-29 11:43:53 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
I am insteresting in it.But I don't know how to do that... ^_Qcould you show some simple code about how it works? thanks a lot.
cofensen at 2007-6-29 11:43:53 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

>...you have to do is to put the JMyClass in your classpath.

I don't know much about JSP but I do know JNI isn't that easy. The shared library also has to be accessible. For server side that means either installing it somewhere or modify the environment. For client side I would expect either an install or some sort of 'plugin' solution would be required.

jschell at 2007-6-29 11:43:53 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

You can write a Java Bean that has some native method to call your C++ code. Then JSP simply calls that Java Bean as if it's a pure Java class. With Java 1.3.1, you use the command tool "javah" to generate a C/C++ header file. Then implement the functions in that header file, compile it into a dll or so (on Unix) file. For step-by-step JNI instructions, see http://web2.java.sun.com/docs/books/tutorial/native1.1/TOC.html

yilin at 2007-6-29 11:43:53 > top of Java-index,Java HotSpot Virtual Machine,Specifications...