0

I have gone through the solutions of tons of questions on the same issue, but none of them seem to work.

Java Version - jdk1.8.0_311

OS - Windows 11

IDE - Vscode

Compiler - g++

Environment Variables -

CPLUS_INCLUDE_PATH - C:\Program Files (x86)\Java\jdk1.8.0_311\include & C:\Program Files (x86)\Java\jdk1.8.0_311\include\win32

LIBRARY_PATH - C:\Program Files (x86)\Java\jdk1.8.0_311\lib\jvm.lib & C:\Program Files (x86)\Java\jdk1.8.0_311\lib\jawt.lib

Build Command - C:/msys64/mingw64/bin/g++.exe -fdiagnostics-color=always -g C:\Users\username\Desktop\jni\main.cpp -o C:\Users\username\Desktop\jni\main.exe -v

Code -

#include <jni.h>
#include <iostream>

int main() {
    using namespace std;
    JavaVM *jvm;
    JNIEnv *env;

    JavaVMInitArgs vm_args;
    JavaVMOption* options = new JavaVMOption[1];
    options[0].optionString = (char*) "-Djava.class.path=.";
    vm_args.version = JNI_VERSION_1_6;
    vm_args.nOptions = 1;
    vm_args.options = options;
    vm_args.ignoreUnrecognized = false;

    jint rc = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    delete options;
    if (rc != JNI_OK) {
        cin.get();
        exit(EXIT_FAILURE);
    }

    cout << "JVM load succeeded: Version " << endl;
    jint ver = env->GetVersion();
    cout << ((ver>>16)&0x0f) << "."<<(ver&0x0f) << endl;
    

    jvm->DestroyJavaVM();
    cin.get();
}
hackedXD
  • 11
  • 4

0 Answers0