JNI_CreateJavaVM () exits with exit code 1

I am trying to call a Java method from C ++ using JNI. For this, I installed jdk1.7.0_51by binding to jdk1.7.0_51\lib\jvm.lib, including jdk1.7.0_51\includeand jdk1.7.0_51\include\win32. using the following code in Visual Studio 2012, I tried to create a Java vm object, but the function always terminates my application with exit code 1 (the function does not return 1: my program terminates completely and sends exit code 1).

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

int main(int argc, char*argv[]){
  JNIEnv* env = nullptr;
  JavaVM* jvm = nullptr;
  JavaVMInitArgs vm_args;
  JavaVMOption options[2];
  options[0].optionString = "-Djava.class.path=.";
  options[1].optionString = "-DXcheck:jni:pedantic";  
  vm_args.version = JNI_VERSION_1_6;
  vm_args.nOptions = 2;
  vm_args.options = options;
  vm_args.ignoreUnrecognized = JNI_TRUE; // remove unrecognized options
  int ret = JNI_CreateJavaVM(&jvm, (void**) &env, &vm_args);
  std::cout << "This code is never reached" << std::endl;
  return 0;
}

OS: Windows 7 (x64)

Compiler: Visual Studio 2012 (x86 / Win32 project)

Java VM: jdk1.7.0_51, i586 (it should be, in my opinion, good, because I am compiling for x86 - otherwise communication with jvm.lib will not work)

: jdk1.7.0_51\jre\bin\client\jvm.dll, jdk1.7.0_51\jre\bin\Server\jvm.dll - ( , ).

.

+4
1

  • jvm.dll . DLL , , DLL , .
  • PATH environement, JRE jvm.dll. "c:\folder with space in name" ( double quotes). set path=c:\folder with space in name;%PATH%. .

.

  • jvm.dll . DLL , , DLL , .
  • jvm.lib
  • LoadLibrary, jvm.dll(escape '\' use '/')
  • GetProcAddress "JNI_CreateJavaVM"
  • typedef ( JNICALL )

, VS2012/Seven64/x86Debug/JDK1.6 " " ( ret == JNI_OK)

+6

Source: https://habr.com/ru/post/1524275/


All Articles