Javah error while using it in JNI

前端 未结 14 1671
离开以前
离开以前 2020-12-01 05:27

Command:

javah -jni JavaHowTo

Result:

error: cannot access JavaHowTo 
class file for JavaHowTo not found

javadoc: error -          


        
相关标签:
14条回答
  • 2020-12-01 05:37

    It worked with me:
    For window:
    If path file .class: D:\workspace\JNI Demo\build\classes\jni\demo and in Netbeans hava package: jni.demo.HelloWorld.java
    First, I buijd file .java into file .class.
    Path file .class: D:\workspace\JNI Demo\build\classes\jni\demo\HelloWorld.class
    Second, I dir D:\workspace\JNI Demo\build\classes
    And javah -jni jni.demo.HelloWorld
    Finally, File result .j created in path: D:\workspace\JNI Demo\build\classes

    0 讨论(0)
  • 2020-12-01 05:38

    I am using Eclipse.

    Command syntax:

    javah -d <outputdir> -classpath <classpath> <fully_qualified_class>
    

    outputdir - The directory where the header file is generated.

    classpath - Contains an absolute path to the directory containing the root package.

    fully_qualified_class - The name of the class containing native methods WITHOUT .class extension

    The following file is generated:

    C:\Users\John\workspace\JNITest\bin\com\canessa\john\jnitest\com_canessa_john_jnitest_CallMyCLib.h

    The contents of the generated header file:

    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class com_canessa_john_jnitest_CallMyCLib */
    
    #ifndef _Included_com_canessa_john_jnitest_CallMyCLib
    #define _Included_com_canessa_john_jnitest_CallMyCLib
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     com_canessa_john_jnitest_CallMyCLib
     * Method:    helloInC
     * Signature: ()V
     */
    JNIEXPORT void JNICALL Java_com_canessa_john_jnitest_CallMyCLib_helloInC
      (JNIEnv *, jobject);
    
    #ifdef __cplusplus
    }
    #endif
    #endif
    
    0 讨论(0)
  • 2020-12-01 05:38
    How to generate a `JNI Header` file from an `Android class` file using `javah` (`.java` or `.class` BOTH work equally well).
    For Eclipse project on Windows:
    Goto the directory where the src, bin and jni folders are (so we can use relative paths to src or bin and jni): cd C:\Android\workspace5\AndroidImageFilter I assume `javah` is in your `PATH` (It is in something like : `C:\Program Files\Java\jdk1.7.0_79\bin\javah.exe`): javah -classpath c:\Android\sdk\platforms\android-19\android.jar;./src/ -d ./jni cn.Ragnarok.NativeFilterFunc ^ ^ ^ ^ ^ ^ ^ ^ ^ | | | | | | | | | Your android:targetSdkVersion="16"----------------------------+ | | | | | | | | | | | | | | | | | | | | | | | path to android.jar ---------+---------------------------------------+ | | | | | | | | | | | | | | | | | | | | | | | | semicolon (;) important ! --------------------------------------------------+ | | | | | | | | | | You can use the source directory (yes you can !) (OR the /bin/classes/ dir)-----+ | | | | | | | | Where to put the output file (cn_Ragnarok_NativeFilterFunc.h in this case)-----------+---+ | | | | The dot (.) spearated full package name path to the .java source file WITH file name --------+ | | File name of a java class -------------------------------------------------------------------------------------+ For Android Studio on Windows e'g': ^ cd C:\Android\workspace5\AndroidImageFilter\app\src\main | and usr java INSTEAD of src ----------------------------------------------------+

    See http://kn-gloryo.github.io/Build_NDK_AndroidStudio_detail/ for a better way.

    If you have a lot of filenames (of java classes) you can use a file with a list of classes.
    If you are on Linux or MAC-OS, use ":" (colon) to separate the directories for classpath rather than ";"
    See reference http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javah.html

    0 讨论(0)
  • 2020-12-01 05:40

    Try

    javah -jni com.example.JavaHowTo
    

    where com.example is your package.

    You also need to run javah from the directory containing com/example/JavaHowTo.class

    e.g. if your structure is

    /home/user/com/example/JavaHowTo.class
    

    run javah from

    /home/user
    
    0 讨论(0)
  • 2020-12-01 05:42

    I successfully use javah every day from my build scripts with the following options:

    javah -d <outputdir> -classpath <classpath> <fully_qualified_class>

    where:

    'outputdir' is the directory where to put the generated header file

    'classpath' contains an absolute path to the directory containing your root package (as mentionned by Glen)

    'fully_qualified_class' is the name of the class containing native methods without .class extension

    -jni option is not required (set by default)

    Anyway you should check your class file has been generated: quite surprised you get a javadoc error too...

    0 讨论(0)
  • 2020-12-01 05:43

    Go to your "bin" directory of your Java project through the cmd Windows command line.

    cd "Path to the bin directory of your java project"
    

    Then,

    javah "Your Package"."Name Of Your Java Class"
    
    0 讨论(0)
提交回复
热议问题