Given a class such as:
class Position {
float x;
float y;
public static native long instance();
public static native float getX(long ptr);
public static native float getY(long ptr);
public static native long delete(long ptr);
}
when generating the native header file, I would like the struct definition corresponding to the fields of the class to be included in the headers. Something like:
struct Position {
float x;
float y;
}
Running the command
javac -classpath bin -d . -h jni src/Position.java
with Java 11 or the command
javah src/Position
with Java 8 doesn't generate the struct.
I found the desired behaviour described in docs for javah (not sure how valid they are currently) stating The .h file contains a struct definition whose layout parallels the layout of the corresponding class.
I would like to know if it's possible to achieve what I described above with javac -h
. If not was it ever possible and if so, what were the reasons for the change? Moreover what alternatives do I have?
Question
What steps can be used to generate a JNI header file for the Java class below?
Steps to follow
javac
using-h
option and "." to write generated files to current directory