Wednesday, December 3, 2014

javah

This always gets me and I've seen a number of questions on the internet so I thought I'd write a simple post how to use javah.

If you have the file Foo.java:


package com;

public class Foo {
    static {
        System.loadLibrary("foo");
    }

   public static native boolean test();
}

And the directory structure is:


TestProject/build/classes/com/Foo.java

from the command prompt, change directories to "TestProject/build/classes", then run:

javah -jni com.Foo

Out will come:



/* DO NOT EDIT THIS FILE - it is machine generated */
#include 
/* Header for class com_Foo */

#ifndef _Included_com_Foo
#define _Included_com_Foo
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_Foo
 * Method:    isdebugged
 * Signature: ()Z
 */
JNIEXPORT jboolean JNICALL Java_com_Foo_isdebugged
  (JNIEnv *, jclass);

/*
 * Class:     com_Foo
 * Method:    getpid
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_com_Foo_getpid
  (JNIEnv *, jclass);

#ifdef __cplusplus
}
#endif
#endif

No comments:

Post a Comment