Learn Java

Step 3: Create Header File with javah

Use below command to create header file from the class file,

javah -jni -cp classes/ com.marakana.jniexamples.Hello

and the directory tree is like below.

├── classes
│   └── com
│       └── marakana
│           └── jniexamples
│               └── Hello.class
├── com_marakana_jniexamples_Hello.h
└── src
    └── com
        └── marakana
            └── jniexamples
                └── Hello.java

com_marakana_jniexamples_Hello.h is generated in the format,

<package name>_<class name>.h

and the code is:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_marakana_jniexamples_Hello */

#ifndef _Included_com_marakana_jniexamples_Hello
#define _Included_com_marakana_jniexamples_Hello
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_marakana_jniexamples_Hello
 * Method:    sayHi
 * Signature: (Ljava/lang/String;I)V
 */
JNIEXPORT void JNICALL Java_com_marakana_jniexamples_Hello_sayHi
  (JNIEnv *, jobject, jstring, jint);

#ifdef __cplusplus
}
#endif
#endif