我有一个要求,我需要从工作区中存在的每个项目构建多个 jar 文件。你能告诉我如何编写一个 build.xml 来创建多个 jar 文件吗?我已经尝试过类似的代码并且知道它的可能,但想知道需要遵循的最佳实践是什么。就我而言,我的工作区中有 5 个项目,我必须创建 5 个不同的 jar。还有一些外部依赖 jar,需要包含在某些项目中才能构建 jar 文件。下面是我为创建两个 jar 文件而编写的示例代码。我为生成 jar 文件而编写的代码如下
<target name="compile" depends="compileVal, compileHib " description="compile the source for all">
</target>
<!-- =============================================
target: compile the source for Valueobjects
============================================= -->
<target name="compileVal" depends="clean" description="description">
<echo message="Creating directory '${target}' if not present "></echo>
<mkdir dir="${target}"/>
<mkdir dir="${Classfiles}"/>
<mkdir dir="${JarLocation}"/>
<javac srcdir="../ValueObjects/src" destdir="${Classfiles}" />
</target>
<!-- =================================
target: compile
================================= -->
<target name="compileHib" depends="clean" description="description">
<echo message="Creating directory '${target}' if not present "></echo>
<mkdir dir="${target}"/>
<mkdir dir="${Classfiles}"/>
<mkdir dir="${JarLocation}"/>
<javac srcdir="src" destdir="${Classfiles}" >
<classpath>
<pathelement location="${libloc}/hibernate3.jar"/>
<pathelement location="${libloc}/hsqldb.jar"/>
<pathelement location="${libloc}/jta.jar"/>
<pathelement location="${libloc}/ojdbc5.jar"/>
<pathelement location="${libloc}/commons-logging-1.1.1.jar"/>
<pathelement location="${libloc}/postgresql-9.1-902.jdbc4.jar"/>
</classpath>
</javac>
</target>
<!-- =================================
target: name
================================= -->
<target name="copy-non-java-files" depends="" description="description">
<copy todir="${Classfiles}" includeemptydirs="false">
<fileset dir="src" excludes="**/*.java" />
</copy>
</target>
<!-- =================================
target: compress
================================= -->
<target name="build_jar" depends="buildValobj, buildHib" description="description">
</target>
<!-- =================================
target: buildValobject jar
================================= -->
<target name="buildValobj" depends="compileVal" description="creates the valueObject jar">
<echo message="Creating the jar to Folder '${JarDest}'"> </echo>
<jar destfile="${JarDest}/${RetValObName}" basedir="${Classfiles}" />
</target>
<!-- =================================
target: buildHibjar
================================= -->
<target name="buildHib" depends="compileHib, copy-non-java-files" description="description">
<echo message="Creating the jar to Folder '${JarDest}'"> </echo>
<jar destfile="${JarDest}/${RetHibName}" basedir="${Classfiles}" />
</target>
<!-- =================================
target: clean
================================= -->
<target name="clean">
<echo message="Cleaning '${target}' folder"></echo>
<delete includeemptydirs="true">
<fileset dir="${target}" includes="**/*"/>
</delete>
</target>
在上面的代码中,我面临的问题是在尝试编译Hib 时,尽管我已经指定了depends="clean"。清洁不会发生。创建了一个 jar,其中包括已经存在的文件以及已移动的新文件。不确定为什么?虽然我指定了 clean,但 clean 操作似乎没有发生。你能告诉我上面缺少什么吗?
请协助。提前致谢