Friday, February 27, 2009

How to call legacy C++ from Java

JavaFirst of all, verify if you realy need the C++ code. There are excellent Java equivalents for many legacy C++ packages. For HEP specific code, you may look at FreeHEP or jHepWork. Other usefull Java packages are noted in the Java In Atlas Wiki page, some are even already installed in the CERN Java Infrastructure.

If you are definitely sure that you do have to call your legacy C++ code, you have several alternatives to implement your bridge:

  1. JACE works ok for calling Java from C++, here everything is automatic. Calling C++ from Java is more tricky, you have to write proxies. Your task can be a little simpler if you don't use standard C++, but Cint dialect of C++. In that case you could use Cint (or Reflex) dictionary to build the proxies. JACE works fine and the JACE discussion forum is active.

  2. JavaRoot allows to call Root functions from Java. The package comes directly from HEP community. It has not been updated for some time, but it may be worth to reanimate. Maybe its author could help you.

  3. I have no experiance with JNIEasy, I just know it exists.

  4. NestedVM allows to compile any (really) code compilable by GCC into Java bytecode. It uses patched GCC. This way, you can compile your legace C++ code directly to Java and your problems are gonne.


By the way, calling Java from C++ is much easier, JACE does the excelent job.

No comments:

Post a Comment