...
For an example of a project using this implementation, you may like to download simple-native-example. That directory contains source archives (eg simple-native-example-i386-Linux-c23cxx5-1.0.23-src.zip), as well as binaries compiled for Linux-i386, and javadocs, and may provide helpful examples of the concepts below.
...
We now need for make to be run after the .class files are built; I did this by attaching an execution to the process-classes phase:. I've also added an ant task to write a file containing the compile-time classpath; this can then be used from the Makefile to build the classpath argument for javah.
| Code Block | ||
|---|---|---|
| ||
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>build-native</id>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<exec<property dirname="src/main/native.classpath" executablerefid="make" failonerror="true"maven.compile.classpath" />
<echo file="${project.build.directory}/compile-classpath" message="${native.classpath}" />
</exec>
<exec dir="src/main/native" executable="make" failonerror="true"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
|
...
We now have our JNI library on the class path, so we need a way of loading it. I created a separate project which would extract JNI libraries from the class path, then load them. Find it at http://opensource.mxtelecom.com/maven/repo/com/wapmx/native/mx-native-loader/1.02/. 3. This is added as a dependency to the pom, obviously.
...
We can make use of the unpacking of includes zips to factor out the complicated parts of the Makefile to a single Makefile which is used by all JNI projects. http://opensource.mxtelecom.com/maven/repo/com/wapmx/native/native-build-scripts/1.214/ provides a demonstration of how this might be done.
...
