tags:

views:

207

answers:

5

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?

+1  A: 

Why not create an executable jar for the java algorithm?

Chung Pow
+4  A: 

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.

Matt Price
+1  A: 

You might be interested by SWIG. "SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby"

Pierre
The OP seems to want it the other way round. SWIG looks interesting, though.
RaphaelSP
+1  A: 

If GCJ is an option for you, it will let you compile your Java program into native code that can be linked with your C++ (again, g++ specifically) program as a library, plus a header file that contains direct CNI mappins of all Java stuff to C++ - packages to namespaces, classes to classes, methods to member functions, and so on.

Pavel Minaev
+1  A: 

Use GCJ to turn the Java into a lib for you to link to.

It might be just as much of a pain as JNI, but at least you won't be loading or dependent on the JRE anymore.

Lou Franco