这里补充所有的完整代码:
Ant的build.xml文件:
=================
build.xml
<?xml version="1.0" encoding="UTF-8" ?>
<project name="JNIDemo" default="All" basedir=".">
<property file="${basedir}/build.properties" />
<path id="Compile.Lib.Path">
</path>
<target name="All" depends="" >
<antcall target="Run" />
</target>
<target name="Init.Dir" depends="" >
<mkdir dir="${Classes.Dir}" />
</target>
<target name="CompileJava" depends="Init.Dir">
<javac
srcdir="${Src.Java.Dir}"
destdir="${Classes.Dir}"
classpathref="Compile.Lib.Path"
>
<include name="**/*.java" />
</javac>
</target>
<target name="JavaH" depends="CompileJava">
<exec dir="${Classes.Dir}" executable="javah.exe" output="${Build.Dir}/javah_result.txt">
<arg line="-jni demo.HelloWorld" />
</exec>
</target>
<target name="BuildDll" depends="JavaH">
<copy todir="${Classes.Dir}">
<fileset dir="${Lib.C.Dir}">
<include name="**/*.lib" />
<include name="**/*.dll" />
</fileset>
</copy>
<exec dir="${Classes.Dir}" executable="${CL.Path}" output="${Build.Dir}/build_dll_result.txt" >
<arg line="-I${Java.Include.Dir} -I${Java.Include.Dir}/win32 -I${Src.Include.Dir} -I${Classes.Dir} -LD ${Src.C.Dir}/HelloWorldImpl.c -Fehello.dll" />
</exec>
</target>
<target name="Run" depends="BuildDll">
<java classname="demo.HelloWorld" dir="${Classes.Dir}" fork="true">
<arg value="-h" />
<classpath>
<pathelement path="${Classes.Dir}" />
</classpath>
</java>
</target>
</project>