author | jcbeyler |
Thu, 14 Mar 2019 09:35:45 -0700 | |
changeset 54128 | c0fccca69aff |
parent 52788 | 241b8151b6b6 |
permissions | -rw-r--r-- |
52788
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
1 |
/* |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
4 |
* |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
8 |
* |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
13 |
* accompanied this code). |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
14 |
* |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
18 |
* |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
21 |
* questions. |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
22 |
* |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
23 |
*/ |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
24 |
|
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
25 |
#include "jni.h" |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
26 |
#include "stdio.h" |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
27 |
#include "stdlib.h" |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
28 |
|
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
29 |
int main(int argc, char** args) { |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
30 |
JavaVMInitArgs vm_args; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
31 |
JNIEnv *env; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
32 |
JavaVM *vm; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
33 |
int i =0; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
34 |
jint result; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
35 |
|
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
36 |
vm_args.version = JNI_VERSION_1_2; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
37 |
vm_args.ignoreUnrecognized = JNI_FALSE; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
38 |
|
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
39 |
JavaVMOption option1[2]; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
40 |
option1[0].optionString="-XX:+PrintCommandLineFlags"; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
41 |
option1[1].optionString="-Xrs"; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
42 |
|
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
43 |
vm_args.options=option1; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
44 |
vm_args.nOptions=2; |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
45 |
|
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
46 |
// Print the VM options in use |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
47 |
printf("initVM: numOptions = %d\n", vm_args.nOptions); |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
48 |
for (i = 0; i < vm_args.nOptions; i++) |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
49 |
{ |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
50 |
printf("\tvm_args.options[%d].optionString = %s\n", i, vm_args.options[i].optionString); |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
51 |
} |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
52 |
|
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
53 |
// Initialize VM with given options |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
54 |
result = JNI_CreateJavaVM( &vm, (void **) &env, &vm_args ); |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
55 |
if (result != 0) { |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
56 |
printf("ERROR: cannot create JAVA VM.\n"); |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
57 |
exit(-1); |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
58 |
} |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
59 |
|
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
60 |
(*vm)->DestroyJavaVM(vm); |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
61 |
} |
241b8151b6b6
8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff
changeset
|
62 |