I have researched this, but the results are either 10+ years old and do not explain what JNI is or if it is the only approach, or the results are for C++ or C#. So here is my question:
How do I run a Java program from a C program, using the following code as an example? What specific changes to I make to the following code to get the C program to successfully call the Java program with parameters?
In the CentOS terminal, I am able to successfully run a Java program when I type the following in the command line:
java -cp . my.package.SomeClass 1 2 3
Similarly, from the same folder in the terminal, I am able to successfully run a C program when I type the following in the command line:
./hello
The code for hello.c
is:
#include <stdio.h>
main() {
printf("Hello World from C!\n");
}
How do I modify the code for hello.c
so that it also runs my.package.SomeClass
with the parameters 1 2 3
?
For example, how do I accomplish the following, but without throwing errors:
#include <stdio.h>
main() {
printf("Hello World from C!\n");
java -cp . my.package.SomeClass 1 2 3 //What is the right syntax here?
}
Edit
I am most interested in answers that show how to call a method, such as SomeClass.someMethod(1,2,3)
.