JNI failed to call FindClass to get the package. Without the package name, the successful Why? was called.

  java, question

The C Plus process starts the jvm virtual machine and then obtains java-related class methods (usingFindClass), if only one class name is successful, but if there is a package, the call will fail with the following code:

 package com;
 import  java.lang.management.ManagementFactory;
 public class MyTest {
 //private static int magic_counter = 777;
 public static boolean start(String path) {
 Out.print ("myteststart:" plus path ");
 return true;
// main.cpp
#include <iostream>
#include <jni.h>
#include <memory.h>

int main()
    char opt1[] = "-Djava.compiler=NONE";
    char opt2[] = "-Djava.class.path=./MyTest.jar";
    //char opt2[] = "-Djava.class.path=.";
    char opt3[] = "-verbose:NONE";

    JavaVMOption options[3];
    options[0].optionString = opt1; options[0].extraInfo = NULL;
    options[1].optionString = opt2; options[1].extraInfo = NULL;
    options[2].optionString = opt3; options[2].extraInfo = NULL;

    JavaVMInitArgs jargv;
    jargv.version = JNI_VERSION_1_6;
    jargv.nOptions = 3;
    jargv.options = options;
    jargv.ignoreUnrecognized = JNI_TRUE;

    JavaVM* jvm = NULL;
    JNIEnv* jenv = NULL;
    jint res = JNI_CreateJavaVM( &jvm, (void**)&jenv, &jargv  );
    if ( 0 != res  )
        return 1;

    jclass jc = jenv->FindClass("/com/MyTest");
    //jclass jc = jenv->FindClass("MyTest");
    //jclass jc = jenv->FindClass("java/lang/String");
    if ( NULL == jc  ) {
        if( jenv->ExceptionOccurred()  )
        else {
            std::cout << "jc null" << std::endl;
        return 1;

    jmethodID jmid = jenv->GetStaticMethodID( jc, "start", "(Ljava/lang/String;)Z");
    if ( NULL == jmid) {
        std::cout << "jmid null" << std::endl;
        return 1;
    else {
        std::cout << "jmid ok" << std::endl;

    jstring jniStr = jenv->NewStringUTF("jni to java");
    jboolean res1 = jenv->CallBooleanMethod( jc, jmid, jniStr);
    if(res1) {
        std::cout << "CallBooleanMethod ok" << std::endl;

    std::cout << "\n";
    std::cout << "Hello, World!" << std::endl;
        return 0;

The relevant commands are as follows:

javac  MyTest.java
 jar cvf MyTest.jar MyTest.class
 ~/jdk/include/ -I~/jdk/include/linux -L~s/jdk/jre/lib/amd64/server -ljvm

This is an error message when running a.out: class not found:
Exception in thread “main” java.lang.NoClassDefFoundError: /com/MyTest
Caused by: java.lang.ClassNotFoundException: .com.MyTest

If the package name com is removed from java, the class is directly found in c-plusMyTest, thenFindClassIt is a success.

Environment: ubuntu 16.04 jdk 1.8

Java needs a path to find the class with registration, just look at the modification.
mkdir com
mv MyTest.jar com/
tar cvf MyTest.jar com