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
|
#if defined(_HPUX) && !defined(_IA64)
#include <dl.h>
#else
#include <dlfcn.h>
#endif // HPUX
#include <errno.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <sstream>
//#include <jni.h>
#include "../../../native/jni_include/jni.h"
#define USE_JNI_VERSION JNI_VERSION_1_4
JavaVM *jvm;
int main(int argc, char** argv)
{
if (argc < 1)
{
printf("Usage: %s [JVM_ARGS]\n", argv[0]);
exit(-1);
}
// Pack the arguments
printf("Pack JVM arguments\n");
JavaVMInitArgs jniArgs;
jniArgs.options = NULL;
jniArgs.version = USE_JNI_VERSION;
jniArgs.ignoreUnrecognized = false;
jniArgs.nOptions = (jint) argc - 1;
printf(" Num options: %d\n", jniArgs.nOptions);
jniArgs.options = (JavaVMOption*) malloc(sizeof (JavaVMOption) * jniArgs.nOptions);
memset(jniArgs.options, 0, sizeof (JavaVMOption) * jniArgs.nOptions);
for (int i = 0; i < jniArgs.nOptions; i++)
{
printf(" Option %s\n", argv[i + 1]);
jniArgs.options[i].optionString = (char*) argv[i + 1];
}
// Launch the JVM
printf("Create JVM\n");
JNIEnv* env;
jint rc = JNI_CreateJavaVM(&jvm, (JNIEnv**) &env, (void*) &jniArgs);
free(jniArgs.options);
if (rc != JNI_OK)
{
printf(" Create JVM failed. (%d)\n", rc);
exit(-1);
}
// Create some resources
printf("Create Java resources\n");
jclass cls = env->FindClass("java/lang/Object");
jmethodID mth = env->GetMethodID(cls, "toString", "()Ljava/lang/String;");
mth = env->GetMethodID(cls, "equals", "(Ljava/lang/Object;)Z");
mth = env->GetMethodID(cls, "hashCode", "()I");
mth = env->GetMethodID(cls, "getClass", "()Ljava/lang/Class;");
// Destroy the JVM
printf("Destroy JVM\n");
jvm->DestroyJavaVM();
printf("Success\n");
}
|