小编典典
是的,您当然可以。这是一个例子:
这是java文件:
public class InvocationHelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
System.out.println("Arguments sent to this program:");
if (args.length == 0) {
System.out.println("(None)");
} else {
for (int i=0; i
System.out.print(args[i] + " ");
}
System.out.println();
}
}
}
还有一些使用它的C ++:
void invoke_class(JNIEnv* env) {
jclass helloWorldClass;
jmethodID mainMethod;
jobjectArray applicationArgs;
jstring applicationArg0;
helloWorldClass = (env)->FindClass("InvocationHelloWorld");
if(! helloWorldClass )
{
std::cerr<
return;
}
mainMethod = (env)->GetStaticMethodID(helloWorldClass, "main", "([Ljava/lang/String;)V");
if(! mainMethod )
{
std::cerr<
return;
}
applicationArgs = (env)->NewObjectArray(1, (env)->FindClass("java/lang/String"), NULL);
applicationArg0 = (env)->NewStringUTF("From-C-program");
(env)->SetObjectArrayElement(applicationArgs, 0, applicationArg0);
(env)->CallStaticVoidMethod(helloWorldClass, mainMethod, applicationArgs);
}
2020-10-15