Tuesday, July 8, 2003 06:31 PM
You can't do it as directly as you probably wish, by having a Java method call a corresponding C++ method through some internal magic.
What you can do with JNI is the following:
- write a Java class that has a bunch of integration methods declared native.
- compile the class
- run the javah tool over the class to generate a header file
- implement the header file in terms of your C++ code and compile it into a DLL
- ship the DLL with your Java app
- invoke your Java app with the -Djava.library.path option so your DLL can be found
It can be made somewhat easier by using a tool like JunC++ion
to allow your native methods to be more easily implemented, but it's still not easy. JunC++ion actually has a simple example for native method integration, so you might want to check it out.