C++ Objects in Java
1 posts in topic
Flat View  Flat View

Posted By:   Stefan_Sechelmann
Posted On:   Thursday, June 19, 2003 05:26 PM

Can I use C++ objects in Java? Everyone
is talking about native method invocation.
I need access to a C++ Object from
the Java environment. Can anyone help?


Re: C++ Objects in Java

Posted By:   Alexander_Krapf  
Posted On:   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.



About | Sitemap | Contact