0

我是 Ant 构建脚本的新手。我正在尝试做以下事情

  1. 删除构建目录
  2. 创建构建目录
  3. 编译代码
  4. 为项目中的每个包创建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:\XXX\XXXWorkspaces\GeoFence\v1.0\GeoFence_Java\build.xml
Detected Java version: 1.6 in: C:\Program Files\Java\jdk1.6.0_14\jre
Detected OS: Windows XP
parsing buildfile E:\XXX\XXXWorkspaces\GeoFence\v1.0\GeoFence_Java\build.xml with URI = file:/E:/XXX/XXXWorkspaces/GeoFence/v1.0/GeoFence_Java/build.xml
Project base dir set to: E:\XXX\XXXWorkspaces\GeoFence\v1.0\GeoFence_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 时,它会退出调试。它不显示任何错误消息。

谁能让我知道脚本中有什么问题?

4

1 回答 1

2

您没有告诉 Ant 运行哪个目标。指定-p(或选择要在 Eclipse Ant 运行器中运行的目标)或定义要在<project>标记中运行的默认目标。

于 2012-06-01T10:21:45.883 回答