forked from ClassViewer/java-gui-launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher_linux_main.c
71 lines (58 loc) · 1.63 KB
/
launcher_linux_main.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// Created by Glavo on 2020.01.10.
//
#include <stdlib.h>
#include "launcher.h"
int main(int argc, char *argv[]) {
loadJVM();
if (libjvm == NULL) {
return EXIT_FAILURE;
}
// jvm methods
jint ans = createJVM();
if (ans != JNI_OK) {
fprintf(stderr, "Create JVM failed");
return ans;
}
jthrowable ex;
jclass mainClass = findClass(APPLICATION_MAIN_CLASS);
ex = (*env)->ExceptionOccurred(env);
if (mainClass == NULL) {
fprintf(stderr, "Main class '" APPLICATION_MAIN_CLASS"' not found");
return EXIT_FAILURE;
}
if (ex != NULL) {
(*env)->ExceptionDescribe(env);
return EXIT_FAILURE;
}
jmethodID mainMethodID = (*env)->GetStaticMethodID(env, mainClass, "main", "([Ljava/lang/String;)V");
ex = (*env)->ExceptionOccurred(env);
if (mainMethodID == NULL) {
fprintf(stderr, "Main method not found");
return EXIT_FAILURE;
}
if (ex != NULL) {
(*env)->ExceptionDescribe(env);
return EXIT_FAILURE;
}
parseCMD(argc, argv);
jobjectArray args = javaArguments();
ex = (*env)->ExceptionOccurred(env);
if (args == NULL) {
fprintf(stderr, "Failed to initialization arguments");
return EXIT_FAILURE;
}
if (ex != NULL) {
(*env)->ExceptionDescribe(env);
return EXIT_FAILURE;
}
destructCMD();
ex = (*env)->ExceptionOccurred(env);
(*env)->CallStaticVoidMethod(env, mainClass, mainMethodID, args);
if (ex != NULL) {
(*env)->ExceptionDescribe(env);
return EXIT_FAILURE;
}
(*vm)->DestroyJavaVM(vm);
return 0;
}