Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 949
Graphics Noob Avatar asked Dec 18 '22 07:12

Graphics Noob


1 Answers

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.

like image 147
Matt Price Avatar answered Jan 05 '23 19:01

Matt Price