在JDK 10中为类文件生成JNI头文件 [英] Generate JNI header files for class files in JDK 10

查看:264
本文介绍了在JDK 10中为类文件生成JNI头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java Native Interface(JNI)的一个组成部分是通过C头桥接JVM代码和本机代码。生成这些头文件的方法过去非常简单:只需在类文件上调用命令行实用程序 javah 即可。然后,此过程将为使用 native 修饰符标记的任何方法生成原型。

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.

从Java 10开始, javah 实用程序已被删除,其建议的替换是javac的新标志-h。如果有可用的Java源文件,则替换工作正常,但是只有编译的类文件可用时才会出现问题。 (引发这个问题的问题是我正在尝试从Scala源生成JNI绑定。我当前的方法是首先编译它们然后在生成的类文件上运行javah。)

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.)

在只有编译的类文件可用的情况下,有没有办法生成C头文件,类似于 javah 习惯的方式?

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?

推荐答案

我们可以使用 gjavah 生成JNI头文件。

We can use gjavah to generate JNI header files.

这篇关于在JDK 10中为类文件生成JNI头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆