从C ++调用Java方法最简单的方法是什么? [英] What is the easiest way to call a Java method from C++?

查看:149
本文介绍了从C ++调用Java方法最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个C ++程序,需要能够读取一个复杂和深奥的文件类型。我已经有一个Java程序来处理这些文件,包括将它们转换成更简单的文件格式的功能。我的想法是,每当我的程序需要从一个复杂的文件中读取信息,让它调用Java方法将其转换为更简单的文件类型,然后写出一个临时文件,我的程序可以很容易地读取。文件足够小,性能将是可以接受的。我在Qt中编写我的程序并在Windows Vista机器上运行它。

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.

我已经研究了使用Java Native Interface,但是我研究它更多的似乎我应该不惜一切代价避免。有没有更好的方法来完成这个,或者我应该继续使用JNI方法吗?

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?

推荐答案

这个?如果不是那么频繁,你可以外出,并在那里做。只需生成命令行就可以了。 JNI的工作,但它是一个痛苦,设置。一旦你设置它应该工作很好。

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.

这篇关于从C ++调用Java方法最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆