C++ to Java(openmp)
I'd appreciate it if you could help on this
Basically what I need to do is to find the best way to load a cpp file through java.
Explaining more, I have a program written in C++ (openmp) and I need to write a Java Gui that will run this file along with some other tasks.
What is the most efficient and easier way to do this? Do you have any online books , or recommendations for it?
Also could this be done through x开发者_运维知识库ml? I mean have the xml structure and load the java's gui file and then the .cpp? How could this work?
Thanks
I think what you are looking for is the JNI: http://en.wikipedia.org/wiki/Java_Native_Interface
Search the web for "JNI getting started" or "JNI tutorial" or "JNI Hello World".
Take a look at Runtime.getRuntime().exec(String);
. This method invokes another application. Here is some example usage:
public void runBtnActionPerformed(ActionEvent evt)
{
try {
Process p = Runtime.getRuntime().exec("./mycppapp"); // or for Windows "mycppapp.exe"
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = br.readLine()) != null)
{
System.out.println(line);
}
} catch (Exception e)
{
// handle here
}
}
Be sure you compiled your C++ application. It is impossible to run the code without compilation. You can try to compile the C++ through Java, using the same method:
int success = Runtime.getRuntime().exec(new String[]{"g++", "mycode.cpp"}).waitFor();
精彩评论