Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i want to write a program in two different languages java and c++ that needs a dynamic and interactive communication between its c++ component and java component.i know there is jni and jna for invoking native methods in java but i do not think this method is appropriate for my purpose.
for example : say a program that its User Interface is written in c++ and other in java, i do not think that communicating these two component can be done through jni and jna. for example Open Office is written in java and c++.
i searched the internet and find some method for Inter-process communication
like shared memory , pipe, signals, Message passing , ... but i don not know that Inter-process communication is what i need. it seems ipc is for communicating software in two different process but my program all is one process(am i right?!)
so my question is : how the programs that its component is written in different language communicate together? and how i can achieve this?
JNI has been exactly created for the purpose that you are describing; why exactly is it not "what you need"?
One other option: message brokers with implementations for different languages, like http://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol
But as you are stressing the latency, this might not be for your.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Java has support for java.lang.Process. This can be used with java.lang.ProcessBuilder or Runtime.exec. With object of java.lang.Process. I can interactive with underlying application by reading output stream/error stream and writing to output stream.
Is there any way/library to do similar thing in either c or c++?
I try popen, but it is unidirectional, i.e. either I can write or read, can't do both.
Any suggestions are welcome. If there is not solution but have some work around, it also welcome.
Update: I am looking solution for Linux Platform.
There is no cross-platform way to launch a new process from either C or C++. Every platform will have its own interface to do so, assuming it has a concept of processes.
The two interfaces you're most likely to come across are the Windows CreateProcess and the POSIX fork/exec.
Since you mentioned reading/writing the subprocess's output/input, you'll also need to use the platform's pipe functions: CreatePipe on Windows or pipe on POSIX-compliant platforms.
There are cross-platform wrappers for all of that, such as Boost Process. None are included with the standard library though, so you'll have to build/install them as you would any other third-party library.
If you can use Managed C++ and .NET, you can use System.Diagnostics.Process, which does the same thing as with java.lang.Process.
Input Redirection
Output Redirection
The caveat is that you need to build your binary as a C++/CLI project, and have .NET as a dependency. You can get around this by putting the managed code in a separate utility library.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Can C++ be used as back-end and Javafx as front-end in the same Application?
And if I do this will the application be an executable (.exe) ? Otherwise is there any way to make it an Executable (.exe) ?
**Edit: Reason - I've got some problem in developing GUI applications with C++. **
You could create a server/client system, where the server is C++ and the client is Java, communicating with some sort of IPC between them. Once there is a disconnect between components, they can be any combination of languages. I'm currently working on a system, where the front end is C# (GUI) and the back end is VB.
Keep in mind that a GUI is about displaying information. There is no rule that says that processing and displaying needs to happen in the same application; written in the same language.
In other words: you "only" need an abstraction layer that allows you to retrieve data from the C++; and to use services on the side.
Your C++ side could provide a RESTful API; or you use JNI to make native calls. Various possibilities, but all of that: advanced topics.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have started a large project, and require some sort of scripting language that can be stored as plain text, and ran within the JVM very fast during execution. I require a language that is simple, customizable, has various Java API's/Libraries to interpret, and can be stored within a large XML file either in an attribute or the inside of a XML node.
This is required so my program can dynamically write code that it will use later, in a neural network.
LUA is the perfect fit for an interpreted language that you want embed in Java:
http://lua-users.org/wiki/LuaImplementations
A more mainstream possibility is to call Jython from Java:
http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html
Another possibility is to use Java only and invoke the compiler at run time:
http://stackoverflow.com/questions/2946338/how-do-i-programmatically-compile-and-instantiate-a-java-class
Using an interpreted language will start the exection of the script faster but the execution itself will be slower. Using the Java compiler will cost more upfront but the execution will be faster and you will be sticking to a single language.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I really like Lua. It's like javascript without so many warts.
One thing I hate about Lua is the 3rd party support. Good luck finding any industrial-grade libraries or frameworks with Lua scripting - Unity 3d has javascript, but no Lua. Qt the same.
I'm wondering if there is a way to "bridge" an arbirtary Lua & some other application. Say, I want 2 programs running - Lua interpreter which handles all the fun stuff, and Java VM which recieves GUI information from Lua (and displays a Swing GUI) and sends user input to Lua.
EDIT: For clarification what I really really want.
From what I remember from CS101, every program has a standard input and output. Is it possible to have:
- Two programs running, 1st in the foreground (java VM), 2nd in background (lua interpreter). I mean, the 2nd one doesn't appear in the task bar. I'm not sure if that's possible, I'm no systems programmer :).
- Java stdin: gui description data + say, glCanvas or some other graphics data. Stdout: user input. Lua's stdin is joined with Java's stdout and vice versa.
I would thank for a code sample if possible.
EDIT: Nevermind, what I looked for was Inter Process Communication.
You can embed, for example, LuaJ in your Java app. Then you will be able to write any logic on Lua and some other things on Java.
Also, you can take a look on projects like kahlua and mochalua (both hosts on googlecode).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a question. Is it do able to hook into a C++ program with Java? And what do I need/make? Because I dont have any Idea how I could do it. I researched already in the internet but I didn't find something that could me help.
I'm very interested in it. ^^
~ Dragon (;
You can use the Java Native Interface.
In computing, the Java Native Interface (JNI) is a programming framework that enables Java code running in a Java Virtual Machine (JVM) to call and be called by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages such as C, C++ and assembly.
These links might be helpful.
Wrapping up a C++ API in Java or .NET
http://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html
http://thebreakfastpost.com/2012/01/21/wrapping-a-c-library-with-jni-introduction/