Open hendriks73 opened 6 years ago
Looks like the regular maven compiler plugin (v3.7.0) can be configured to spit out the headers like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-h</arg>
<arg>${project.build.directory}/native/include</arg>
</compilerArgs>
</configuration>
</plugin>
But... to use the plugin on Java9/10, a dependency definitely needs to be updated. Please see https://github.com/mojohaus/maven-native/pull/18.
The 1.0-alpha-9 version was released. That milestone should be closed and this issue bumped to the next milestone (unless it was already fixed).
@hendriks73 is this fixed in alpha-9?
No, it's not.
Java9 and 10 do not have a javah
executable anymore. So the native plugin should either
javac
with the appropriate flags (not sure, if that's possible)javah
is not supported anymoreThat aside, users can use the regular compiler plugin to produce header files, as shown above.
There is one project - https://github.com/Glavo/gjavah it looks like an implementation of javah in pure java. It is mit licensed. Maybe it can be used instead of javah?
Given that javac -h
works even better than javah
, I don't really see why this even needs to be maintained anymore. It's easy enough to update the maven-compiler-plugin
to use -h
and, if necessary, it's not too difficult to use profiles to support different Java versions to support pre- and post-Java8, which added the -h
flag to javac
.
This is true but javac -h
becomes useless when working with other JVM languages as it only operates on .java
source files 😕
Given that
javac -h
works even better thanjavah
, I don't really see why this even needs to be maintained anymore. It's easy enough to update themaven-compiler-plugin
to use-h
and, if necessary, it's not too difficult to use profiles to support different Java versions to support pre- and post-Java8, which added the-h
flag tojavac
.
I see that we can change org.codehaus.mojo.natives.javah.JavahExecutable to use javac -h
instead of javah
, but I believe the command-line changed from referring to the class file with its package name to using the .java file. Let's say I successfully branch this project, make that small change, build and install the plugin for maven, how would I call the plugin differently?
Also, if I understand correctly, this plugin allows you to define a build artifact that builds the JNI header and the native library (.so, .dll, .dylib) in the same build call. Do I have to separate those into two steps if I use the maven-compiler-plugin
as noted above?
What I've done for now is to hack the org.codehaus.mojo.natives.javah.JavahExecutable
to use javac -h
instead of javah
, and modified my pom.xml to use the .java
source path for the <javahClassName>
property instead of using the dot-separated package and class name. I can build it with JDK8 that way. Next step is to try with a newer JDK.
Is this fix for JavahExecutable already available? I'm having an issue with another project that relies on the maven-native plugin.
I am also interested in this fix.
Java 10 got rid of the
javah
executable and replaced it withjavac -h
.