#include #include #include #include #include #include "../src/mlp_priv.h" #include "mlp_java_priv.h" mlp_runtime_interface *_mlp_java_init(mlp_context *ctx){ mlp_runtime_interface *iface = MLP_GENERATE_INIT(iface, java) ; return iface ; } void *_mlp_java_new_runtime(mlp_context *ctx, const void *opts){ JavaVMInitArgs vm_args ; vm_args.version = JNI_VERSION_1_2 ; vm_args.options = (JavaVMOption *)malloc(1 * sizeof(JavaVMOption)) ; vm_args.nOptions = 0 ; vm_args.ignoreUnrecognized = JNI_FALSE ; char *classpath = getenv("CLASSPATH") ; if (classpath != NULL){ char *cp = (char *)malloc((strlen(classpath) + 32) * sizeof(char)) ; sprintf(cp, "-Djava.class.path=%s", classpath) ; vm_args.options[vm_args.nOptions++].optionString = cp ; } JavaVM *jvm = NULL ; JNIEnv *env = NULL ; jint res = JNI_CreateJavaVM(&jvm, (void **)&(env), &vm_args) ; if (res < 0) { mlp_context_set_error(ctx, MLP_NEW_RUNTIME_ERROR, "Can't create Java VM\n") ; return NULL ; } return (void *)jvm ; } void _mlp_java_delete_runtime(mlp_context *ctx, void *runtime){ /* (*(this->jvm))->DestroyJavaVM(this->jvm) ; */ }