0

my question is how to call running Java code from running C++ code and vice versa. There are several posts available concerned with calling compiled c++ files from Java or JVM from C unsing Java Native Interface (JNI) or Java Native Access (JNA). However, to me this seems not to be an adequate way to call running code as only compiled libraries are invoked in the examples.

My case looks as follows. There are two applications running on a local computer. One application is Eclipse- and Java-based. The other application is C++-based. I need to make them communicating in both directions. Maybe this is a case for RPC? But I do not need to communicate via web.

I think RCP may be a way but it seems oversized to me as i do not want to communicate over web and I do not know how to use RCP in this context. I am searching for a smarter solution.

Is there any experience that can help me?

Thanks and Regards

Rob

  • 1
    There are various means of interprocess communication available to you. I've always been a fan of the named pipe, but it may be too simple an abstraction for you. Remember that while a full network-capable RPC mechanism may seem a bit like overkill, you can use existing libraries to do the hard work and it does give you scope to distribute your applications across a network or multiple virtual machines on the same host in the future, etc. – Rook Jun 15 '12 at 15:58

2 Answers2

1

You may wish to look at my C++ to Java RPC solution. Given a Java class, it generates a C++ client stub and Java server stub.

https://github.com/danfickle/cppToJavaRpcStubGenerator

Edit: I think CORBA is the 'standard' solution. However, the 1000 page book Java and CORBA that I have on my bookshelf (and haven't read) suggests there is a learning curve. You may also wish to look into MessagePack, Thrift, ActiveMQ, etc. Sorry, I couldn't be more help.

Daniel
  • 36
  • 2
  • Thank you Daniel! Still, RCP seems too oversized to me and has some performance issues. Performance is important to my case as both of my applications will exchange millions of messages in a short period of time. Is a message exchange between a local java application and a local C++ application really so unusual that there is no standard solution available? – user1459107 Jun 16 '12 at 17:38
0

JNI allows you to link C++ and Java code; however, the both are the same program.

If you wanted to have one program call another program, the easiest way is to use a network enabled technology. RPC, CORBA, client/server sockets, or any other means including a network will suit you nicely.

Harder non-networking stack solutions exist, like shared memory, semaphores, pipes, etc; however, they require an operating system that supports them, and are subject to constraints on how they are used, plus you will need to find language bindings for both languages using them.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • Thank you Edwin! But I do not know how to start. Should I use RMI to call the C++ application from Java? Which kind of RCP can I use to call the Java application from the C++ application? I am not that familar with RCP. – user1459107 Jun 15 '12 at 16:15