我已经尝试在 pom 中传递这个参数,但它无法识别它。从 jdk 8 开始,我们不必手动运行 javah 来生成头文件,而是可以将 -h 参数传递给 javac 并在编译时生成头文件。因此,如果我可以将“-h dir”传递给 maven 编译器插件,我可以在运行 mvn compile 时生成头文件
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<compilerArgs>
<arg>-verbose</arg>
<arg>-h .</arg>
</compilerArgs>
</configuration>
</plugin>
但是当我运行 mvn install 我得到这个
[信息] 构建失败
[信息] ----------------------------------------------- -------------------------
[信息] 总时间:2.936 秒
[INFO] 完成时间:2018-11-07T14:52:49+05:30
[INFO] 最终内存:9M/155M
[信息] - - - - - - - - - - - - - - - - - - - - - - - - -------------------------
[错误] 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project adiesha-native: Fatal error compiling: invalid flag: -h 。 -> [帮助 1]
有没有其他方法可以用 maven 来做到这一点,或者我是否必须使用“javac -h dir”手动创建它们
任何帮助将不胜感激
最佳答案
我的 maven 构建有同样的错误“无效标志:-h 目标/ header ”。
我尝试了上面 Gyro Gearless 的建议。我将原来的“-h 目标/标题”分成“-h”和“目标/标题”。那解决了我的问题。现在我项目中的所有 jni 标题都正确生成并放置在目标/标题中。
这是我的 pom.xml 中的整个编译器插件配置部分:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<compilerArgs>
<arg>-h</arg>
<arg>target/headers</arg>
</compilerArgs>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
使用这个 pom,命令 'mvn compile' 足以生成 JNI 头文件。请注意,'mvn clean' 不会删除以前生成的标题。
关于java - 如何将 -h 参数传递给 maven 编译器插件以创建 JNI 头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53186355/