简体   繁体   English

Java app & C++ app集成/通讯

[英]Java app & C++ app integration / communication

We have two code bases, one written in C++ (MS VS 6) and another in Java (JDK 6).我们有两个代码库,一个用 C++(MS VS 6)编写,另一个用 Java(JDK 6)编写。 Looking for creative ways to make the two talk to each other.寻找创造性的方法让两人互相交谈。


More Details:更多细节:

Both applications are GUI applications.这两个应用程序都是 GUI 应用程序。
Major rewrites or translations are not an option.主要的重写或翻译不是一种选择。
Communications needs to be two-way.沟通需要双向。 Try to avoid anything involving writing files to disk.尽量避免涉及将文件写入磁盘的任何事情。

So far the options considered are:到目前为止,考虑的选项是:

  • zero MG零毫克
  • RPC RPC
  • CORBA科尔巴
  • JNI JNI
  • Compiling Java to native code, and then linking将 Java 编译为原生代码,然后链接

Essentially, apart from the last item, this boils down to a choice between various ways to achieve interprocess communication between a Java application and a C++ application.本质上,除了最后一项之外,这归结为在 Java 应用程序和 C++ 应用程序之间实现进程间通信的各种方法之间进行选择。 Still open to other creative suggestions!仍然愿意接受其他创意建议!

If you have attempted this, or something similar before please chime in with your suggestions, lessons learnt, pitfalls to avoid, etc.如果您之前尝试过此操作或类似的操作,请提出您的建议、经验教训、要避免的陷阱等。


Someone will no doubt point out shortly, that there is no one correct answer to this question.毫无疑问,很快就会有人指出,这个问题没有一个正确的答案。 I thought I would tap on the collective expertise of the SO community anyway, and hope to get many excellent answers.我想无论如何我都会利用 SO 社区的集体专业知识,并希望得到许多优秀的答案。

Well, it depends on how tightly integrated you want these applications to be and how you see them evolving in the future.嗯,这取决于您希望这些应用程序的集成程度以及您如何看待它们在未来的发展。 If you just want to communicate data between the two of them (eg you want one to be able to open a file written by the other, or read a stream directly from the other), then I would say that protocol buffers are your best bet.如果您只想在两者之间进行数据通信(例如,您希望一个能够打开另一个写入的文件,或者直接从另一个读取 stream),那么我会说协议缓冲区是您最好的选择. If you want the window rendered by one of these GUI apps to actually be embedded in a panel of the other GUI app, then you probably want to use the JNI approach.如果您希望这些 GUI 应用程序之一呈现的 window 实际嵌入到另一个 GUI 应用程序的面板中,那么您可能想要使用 JNI 方法。 With the JNI approach, you can use SWIG to automate a great deal of it, though it is dangerously magical and comes with a number of caveats (eg it doesn't do so well with function overloading).使用 JNI 方法,您可以使用SWIG将其中的大部分自动化,尽管它非常神奇并且带有许多警告(例如,它在 function 重载时效果不佳)。

I strongly recommend against CORBA, RMI, and similarly remote-procedure-call implementations, mostly because, in my experience, they tend to be very heavy-weight and consume a lot of resources.我强烈建议不要使用 CORBA、RMI 和类似的远程过程调用实现,主要是因为根据我的经验,它们往往非常重量级并且消耗大量资源。 If you do want something similar to RMI, I would recommend something lighter weight where you pass messages, but not actual objects (as is the case with RMI).如果您确实想要类似于 RMI 的东西,我会建议您在传递消息时使用更轻的重量,而不是实际的对象(就像 RMI 一样)。 For example, you could use protocol buffers as your message format, and then simply serialize these back and forth across normal sockets.例如,您可以使用协议缓冲区作为您的消息格式,然后简单地在普通 sockets 中来回序列化这些。

Kit Ho mentioned XML or JSON, but protocol buffers are significantly more efficient than either of those formats and also have notions of backwards-compatibility built directly into the definition language. Kit Ho 提到了 XML 或 JSON,但协议缓冲区比这两种格式中的任何一种都更有效,并且还具有直接内置到定义语言中的向后兼容的概念。

Use Jacob ( http://sourceforge.net/projects/jacob-project ), JCom ( http://sourceforge.net/projects/jcom ), or j-Interop ( http://j-interop.org ) and use COM for communication. Use Jacob ( http://sourceforge.net/projects/jacob-project ), JCom ( http://sourceforge.net/projects/jcom ), or j-Interop ( http://j-interop.org ) and use COM 用于通讯。

Since you're using Windows, I'd suggest using DDE (Dynamic Data Exchange) .由于您使用的是 Windows,我建议使用DDE (Dynamic Data Exchange) There's a Java library available from Java Parts . Java Parts提供了一个 Java 库。

Dont' know how much data and what type of data you wanna transfer and communicate.不知道您要传输和交流多少数据以及什么类型的数据。 But to simplify the way, I suggest using XML or Json based on HTTP protocol.但为了简化方法,我建议使用基于 HTTP 协议的 XML 或 Json 协议。

Since there are lots of library for both applications and you won't spend too much effort to implement and understand.由于这两个应用程序都有很多库,因此您不会花费太多精力来实现和理解。

More, if you have additional applications to talk with, it is not hard since both tech.此外,如果您有其他应用程序要讨论,这并不难,因为这两种技术都可以。 are cross-languages.是跨语言的。

correct me if i am wrong如果我错了,请纠正我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM