Search code examples
javajava-native-interfacenativejavah

Javah work some class, but doesnt work some class


There are a alot of questions about javah, but I couldnt find any solution for my issue for 3 day.

My java file work normally and no error. I copied my java file "I2CInterface.java" to "jdk/bin" directory. Then "javac I2CInterface.java" the I2CInterface.class created succesfully. But "javah -jni I2CInterface" is not work the header file cant created. The error is "class not found" I try with classpath but not work. I set my environtmental and add path C:\Program Files\Java\jdk1.8.0\bin. No work. That is interesting javah work on some class and it can create header. But on this class and some class not work.

The problem is about java file? My java file below.

package com.multitek.ipintercomflatunit;


public class I2CInterface { 

private static native int i2cwrite(byte[] data);    
private static native byte[] i2cread(int data_len);

public static int write(byte[] data) {
    return(i2cwrite(data));
}
public static byte[] read(int data_len) {
    return(i2cread(data_len));
}

static 
{
    System.loadLibrary("i2cinterface");
}

Solution

  • If the class is in a package, say xxx, the correct command line will be

    javah xxx.I2CInterface 
    

    I copied my java file "I2CInterface.java" to "jdk/bin" directory

    Why? There's no need to do that. Don't pollute the Java installation directory with your own stuff. Leave it where it was and compile it there. Adjust your PATH if necessary so you can execute the JDK tools.