首页 > 解决方案 > 在 pom.xml 中打开 JDK 11 和 javah

问题描述

我将我的 java 版本从 java 8 切换到 java 11 ,似乎在 java 11 中 javah 已从 JDK bin 文件夹中删除,然后我在 pom.xml 中执行 javah 命令,如下所示

<execution>
      <id>javah</id>
      <goals>
         <goal>exec</goal>
      </goals>
      <phase>compile</phase>
      <configuration>
          <executable>javah</executable>
              <arguments>
                  <argument>-classpath</argument>
                  <argument>${project.build.outputDirectory}</argument>
                  <argument>-d</argument>
                  <argument>${build.path}/include</argument>
               </arguments>
      </configuration>
 </execution>

由于 javah 已从 JDK 11 中删除,如何在我的 pom 中将上述 javah 命令替换为 javac -h 以使用 java 11

我得到的错误是

无法在项目 myProject 上执行目标 org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (javac -h):命令执行失败。:进程退出并出现错误:2(退出值:2)

任何想法?谢谢

标签: javamavenpom.xmljava-11

解决方案


您应该将执行修改为:

<execution>
    <id>javach</id>
    <goals>
        <goal>exec</goal>
    </goals>
    <phase>compile</phase>
    <configuration>
        <executable>javac</executable>
        <arguments>
            <argument>-classpath</argument>
            <argument>${project.build.outputDirectory}</argument>
            <argument>-h</argument>
            <argument>${build.path}/include</argument>
        </arguments>
    </configuration>
</execution>

基于javac --help

  -h <directory>
        Specify where to place generated native header files

推荐阅读