What is the easiest way to call a Java method from C++?

c++, java, java-native-interface

Solution

How often do you need to do this? If it's not that often you can shell out and do it there. Just generate the command line to do it. JNI works, but it's a bit of a pain to get set up. Once you have it set up it should work just fine.

Problem

I'm writing a C++ program which needs to be able to read a complex and esoteric file type. I already have a Java program for handling these files which includes functionality to convert them into simpler file formats. My idea is, whenever my program needs to read info from a complex file, to have it call the Java method to convert it to the simpler file type, then write it out to a temp file which my program can easily read. The files are small enough that performance will be acceptable. I'm writing my program in Qt and running it on a Windows Vista machine. I've looked into using Java Native Interface, but the more I look into it the more it seems I should avoid it at all costs. Is there a better way to accomplish this, or should I continue with the JNI approach?

Original source