-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
40 lines (37 loc) · 1.41 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include "src/share/vm/prims/jni.h"
/* old main() */
//int main() {
// VM* vm = new VM();
// vm->start();
// delete vm;
// std::cout << "Hello, World!" << std::endl;
// return 0;
//}
/* Use jni to invoke main class's main method
* argv should be parsed into JavaVMOption data structure and
* be passed to JNI_CreateJavaVM. The class name part of argv
* should be used to find main class. For now, we assume that
* argv only contains class name.
*/
int main(int argc, char** argv) {
JavaVM *jvm; /* denotes a Java VM */
JNIEnv *env; /* pointer to native method interface */
JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */
JavaVMOption* options = new JavaVMOption[1];
options[0].optionString = "-Djava.class.path=/usr/lib/java";
vm_args.version = 0; /* not sure what value this arg should be */
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = false;
/* load and initialize a Java VM, return a JNI interface
* pointer in env */
JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
const char* main_class = "Inc";
/* invoke the main method using the JNI */
jclass cls = env->FindClass(main_class);
// jmethodID mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
// env->CallStaticVoidMethod(cls, mid, 100);
/* We are done. */
// jvm->DestroyJavaVM();
}