Hi,
I was trying to port my ant project with JNI over to maven and I
encountered a problem with maven-antrun-plugin with an error message:
“Can’t load javah”.
Here are the details:
I have an ant build script that also generates jni files using ant’s javah
task. I try to port it to maven, so only the JNI part would be done in the
ant, other java files would be handled by maven directly.
The problem is that when I run from maven ( mvn clean install ), I got the
error like:
clean:
[mkdir] Created dir: c:\Project\javah_tryout\target\javah_headers
compile:
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] An Ant BuildException has occured: The following error occurred
while executing this line:
c:\Project\javah_tryout\build.xml:19: Can't load javah
around Ant part ...<ant inheritRefs="true" target="compile"
inheritAll="true"/>... @ 8:63 in
c:\Project\javah_tryout\target\antrun\build-compile.xml
com.sun.tools.javah.Main
[INFO]
------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Mon Dec 19 14:35:43 EST 2011
[INFO] Final Memory: 26M/62M
[INFO]
------------------------------------------------------------------------
Yet, I can manually run the ant build.xml w/o problems. (ant compile) It
did generate the .h files.
I think there are classpath issues so that the ant-run plugin can’t locate
and pass sun’s tools.jar to the classpath of the ant. But I can’t figure
out from the ant-run-plugin how to do that. Hope someone has gone through
this and knew the answers. Thanks.
--peter
Here are my pom.xml and ant build.xml:
<!—pom.xml à
<build>
..
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>build-javah</id>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="compile">
<property name="compile_classpath"
refid="maven.compile.classpath"/>
<property name="runtime_classpath"
refid="maven.runtime.classpath"/>
<property name="test_classpath"
refid="maven.test.classpath"/>
<property name="plugin_classpath"
refid="maven.plugin.classpath"/>
<ant target="compile" inheritRefs="true"
inheritAll="true" />
</target>
</configuration>
</execution>
</executions>
</plugin>
..
</build>
<!—ant build.xml à
<project name="java_tryout" default="compile">
<!-- directory definition -->
<property name="src" value="${basedir}/src/main/java"/>
<property name="build" value="${basedir}/target/javah_headers"/>
<target name="compile" depends="clean">
<mkdir dir="${build}"/>
<javah destdir="${build}" force="yes" classpath="${src}" verbose="true">
<class name="sli.tryout.NativeSome"/>
</javah>
</target>
</project>
--peter