Generate JNI header files for class files in JDK 10

Jakob Odersky :

An integral part of the Java Native Interface (JNI), is the bridging of JVM code and native code through C headers. The way to generate these header files used to be quite straight forward: simply call the command line utility javah on class files. This process would then generate prototypes for any method marked with the native modifier.

As of Java 10 however, the javah utility has been removed, and its suggested replacement is a new flag "-h" to javac. The replacement works fine if one has the Java source files available, however falls short in cases where only compiled class files are available. (The issue that sparked this question is that I'm trying to generate JNI bindings from Scala sources. My current approach has been to compile them first and then run javah over the resulting class files.)

In a situation where only compiled class files are available, is there a way to generate C header files, similar to the way javah used to?

Glavo :

We can use gjavah to generate JNI header files.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=439521&siteId=1