title: JVM can't find class when using JNI from C++
body: <p>I'm trying to call JAVA methods from C++ by JNI. First of all, I got <a href="https://www.codeproject.com/Articles/993067/Calling-Java-from-Cplusplus-with-JNI" rel="nofollow noreferrer">this</a> example, tried it out. I changed the path of JDK and after that I could run the examples and they properly worked.</p>
  
  <p>After that, I tried to import my own JAR file and use one class from it. I copied the code from the example and replaced the classpath and classname with my own:</p>
  
  <pre><code>void MyCPPClass::CallJava()
  {
      JavaVM *jvm;                // Pointer to the JVM (Java Virtual Machine)
      JNIEnv *env;                // Pointer to native interface
  
      //==================== prepare loading of Java VM ============================
  
      JavaVMInitArgs vm_args;                        // Initialization arguments
      JavaVMOption* options = new JavaVMOption[ 1 ];   // JVM invocation options
      options[ 0 ].optionString = "-Djava.class.path=MyJar.jar";   // where to find java .class
      vm_args.version = JNI_VERSION_1_8;             // minimum Java version
      vm_args.nOptions = 1;                          // number of options
      vm_args.options = options;
      vm_args.ignoreUnrecognized = false;     // invalid options make the JVM init fail
  
      //================= load and initialize Java VM and JNI interface ===============
  
      jint rc = JNI_CreateJavaVM( &amp;jvm, (void**)&amp;env, &amp;vm_args );  // YES !!
      delete options;    // we then no longer need the initialisation options. 
  
      //========================= analyse errors if any  ==============================
      // if process interuped before error is returned, it's because jvm.dll can't be 
      // found, i.e.  its directory is not in the PATH. 
  
      if( rc != JNI_OK )
      {
          exit( EXIT_FAILURE );
      }    
  
      jclass cls1 = env-&gt;FindClass( "aaa/bbb/MyClass" );
      ...
  }
  </code></pre>
  
  <p>The JAR contains only one class <code>aaa.bbb.MyClass</code> and it's made with IntelliJ IDEA and <code>mvn package</code> command. I copied the JAR file next to my executable.</p>
  
  <p>A value of <code>rc</code> is always 0 (<code>JNI_OK</code>), but the value of <code>cls1</code> is always <code>NULL</code>. I think that JVM can find the JAR, because when I'm debugging I can't delete the JAR after <code>FindClass</code>.</p>
  
  <p>The JAR file contains the MyClass.class file, I checked it. </p>
  
  <p>I have checked some previous questions ( <a href="https://stackoverflow.com/questions/40911447/load-jar-file-in-c-using-jni">1</a>, <a href="https://stackoverflow.com/questions/17989206/how-to-load-jar-file-in-c-using-jni">2</a>, <a href="https://stackoverflow.com/questions/2025397/can-c-application-load-the-jar-file-using-jni">3</a> and some others) yet, but I couldn't get where I made a mistake.</p>
  
  <p><strong>UPDATE:</strong> I tried to copy the MyClass.class file and MyJar.jar file into the directory of the example linked before, and JVM can't find <code>MyClass</code>. It's possible that something missing from my java source file? The package declaration is correct.</p>
  
  <p>What can cause that JVM can't find <code>MyClass</code>?</p>