Search code examples
javajava-native-interfacejavacjavah

The command "javac -h" and "javah -jni" can't find the file I specified


I'm trying to generate the header file (MyClass.h) using the command javah -jni MyClass.java since I use the JDK 1.8 but I also tried with the other version of the command javac -h MyClass.java but I always get the following result in my terminal :
enter image description here

All my .java or .class file are in this folder.

Thank you for the help
[edit] I also tried with the .class file but the output is the same with javac -h but with javah -jni I get the following output :
enter image description here


Solution

  • Try to compile SimpleJNI.java first and then execute javah command.

    Sample class

    public class SimpleJNI
    {
       public static void someMethod()
       {
          System.out.println("Some method");
       }
    }
    

    Compile is using javac with -classpath if there is any external dependency required.

    javac -classpath <path_to_dependency> SimpleJNI.java 
    

    or without -classpath if there is no dependency

    javac SimpleJNI.java
    

    then execute javah with your .class file

    javah SimpleJNI