我是 Ant 构建脚本的新手。我正在尝试做以下事情
- 删除构建目录
- 创建构建目录
- 编译代码
- 为项目中的每个包创建 jar 文件
为此,我编写了以下代码
<?xml version="1.0"?>
<project name="test" basedir=".">
<property name="build.lib" value="dist"/>
<property name="prefix" value="XXX"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="build.classes" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<path id="compile.classpath">
<fileset dir="OpenJPA_lib_jar">
<include name="*.jar"/>
</fileset>
</path>
<macrodef name="build_jar">
<attribute name="name"/>
<sequential>
<jar destfile="${build.lib}/${prefix}-@{name}.jar">
<fileset dir="${build.classes}">
<include name="zumigo/geofence/@{name}/**"/>
</fileset>
</jar>
</sequential>
</macrodef>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<echo message="Build dir = ${build.dir}"/>
<target name="prepare">
<mkdir dir="${build.dir}"/>
</target>
<target name="compile" depends="prepare">
<javac destdir="${build.classes}" debug="true" srcdir="${src.dir}">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="run" depends="compile">
<build_jar name="common"/>
<build_jar name="dal"/>
<build_jar name="databeans"/>
<build_jar name="dataobject"/>
<build_jar name="dto"/>
<build_jar name="exception"/>
</target>
</project>
当我使用详细选项在命令行上执行 ant 脚本时,它给了我以下输出
Apache Ant(TM) version 1.8.3 compiled on February 26 2012
Trying the default build file: build.xml
Buildfile: E:XXXXXXWorkspacesGeoFencev1.0GeoFence_Javabuild.xml
Detected Java version: 1.6 in: C:Program FilesJavajdk1.6.0_14jre
Detected OS: Windows XP
parsing buildfile E:XXXXXXWorkspacesGeoFencev1.0GeoFence_Javabuild.xml with URI = file:/E:/XXX/XXXWorkspaces/GeoFence/v1.0/GeoFence_Java/build.xml
Project base dir set to: E:XXXXXXWorkspacesGeoFencev1.0GeoFence_Java
parsing buildfile jar:file:/D:/Downloads/apache-ant-1.8.3/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/D:/Downloads/apache-ant-1.8.3/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
[macrodef] creating macro build_jar
[echo] Build dir = build
BUILD SUCCESSFUL
Total time: 0 seconds
我什至尝试在 eclipse 中调试脚本。调试点设置在"准备"目标处,当我们按 F5 时,它会退出调试。它不显示任何错误消息。
谁能让我知道剧本有什么问题?
你没有告诉蚂蚁要运行哪个目标。指定-p
(或选择要在 Eclipse Ant 运行器中运行的目标)或定义要在 <project>
标记中运行的缺省目标。