'Open JDK 11 and javah in pom.xml

I switched my java version from java 8 to java 11 , and it seems that in java 11 javah is removed from JDK bin folder, before I was executing the javah command in my pom.xml like below

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

Since javah has been removed from JDK 11 how can I replace the above javah command with javac -h in my pom to work with java 11

The error I get is

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (javac -h) on project myProject: Command execution failed.: Process exited with an error: 2 (Exit value: 2)

Any idea? Thanks



Solution 1:[1]

You should modify your execution as :

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

based on the the javac --help

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

Solution 2:[2]

Here is another way to generate the sources, this time by adding on to the maven-compiler-plugin:

<compilerArgs>
    <arg>-h</arg>
    <!-- where to put include files (change to whatever) -->
    <arg>${project.basedir}/src/main/c++/include</arg>
    <arg>-d</arg>
    <!-- where to put the generated .class files (probably don't change this) -->
    <arg>${project.build.outputDirectory}</arg>
</compilerArgs>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Naman
Solution 2