如何从java调用c ++功能 [英] How to call c++ functionality from java

查看:160
本文介绍了如何从java调用c ++功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要是GUI的Java程序,它显示了从c ++命令行工具写入xml文件的数据。现在我想在java程序中添加一个按钮来刷新数据。这意味着我的程序必须调用c ++功能。

I have a Java program that is mostly GUI and it shows data that is written to an xml file from a c++ command line tool. Now I want to add a button to the java program to refresh the data. This means that my program has to call the c++ functionality.

是通过系统调用从java调用程序的最佳方法吗?
将为mac os和windows编译c ++程序,并且应始终与java程序位于同一目录中。

Is the best way to just call the program from java through a system call? The c++ program will be compiled for mac os and windows and should always be in the same directory as the java program.

我想生成一个可执行文件可以将c程序存储在jar中并从我的程序中调用吗?

I would like to generate an executable can the c program be stored inside the jar and called from my program?

推荐答案

假设没有更好的通信方法可用(SOAP,ICE,套接字等),我会使用 Runtime.exec()。 JNI可以直接用于界面,但我不推荐它。不,你不能把一个可执行文件放在jar中。嗯,你可以,但你不能运行它,因为shell不知道如何运行它。

Assuming no better communication method is available (SOAP, ICE, Sockets, etc), I'd call the executable using Runtime.exec(). JNI can be used to interface directly, but I wouldn't recommended it. No you can't put an executable in the jar. Well you can, but you can't run it, since the shell doesn't know how to run it.

这篇关于如何从java调用c ++功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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