猿问

如何将 -h 参数传递给 maven 编译器插件以创建 JNI 头文件

我已经尝试在 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”手动创建它们


牛魔王的故事
浏览 203回答 1
1回答

浮云间

我的 maven 构建有同样的错误“无效标志:-h 目标/标头”。我尝试了上面 Gyro Gearless 的建议。我将原来的“-h 目标/标题”分成“-h”和“目标/标题”。那解决了我的问题。现在我项目中的所有 jni 标题都正确生成并放置在目标/标题中。这是我的 pom.xml 中的整个编译器插件配置部分:&nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-compiler-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>3.7.0</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <compilerArgs>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <arg>-h</arg>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <arg>target/headers</arg>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</compilerArgs>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <source>11</source>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <target>11</target>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>使用这个 pom,命令 'mvn compile' 足以生成 JNI 头文件。请注意,'mvn clean'不会删除以前生成的标题。
随时随地看视频慕课网APP

相关分类

Java
我要回答