<?xml version="1.0" encoding="UTF-8"?>
<!-- mkdir javac jar clean 在控制台或者MyEclipse指定project的,而不是在构建文件<project name="OurProject" default="archive" basedir="..\">指定-->
<project name="OurProject" default="archive" basedir="..\">
<target name="init" description="创建文件夹">
<mkdir dir="build\classes" description="用来放置类文件"/>
<mkdir dir="dist" description="用来放置打包文件"/>
</target>
<target name="compile" depends="init" description="编译源文件">
<javac srcdir="src" destdir="build/classes"></javac>
</target>
<target name="archive" depends="compile" description="打包">
<jar destfile="dist\project.jar" basedir="build\classes"></jar>
</target>
<target name="clean" depends="init" description="清除类文件和打包文件">
<delete dir="build" description="如果该文件夹有打开的文件,删除失败"></delete>
<delete dir="dist"></delete>
</target>
</project>
<!--
在控制台或者MyEclipse指定project的,而不是在构建文件<project name="OurProject" default="archive" basedir="..\">指定
当两方面同时指定,以控制台或者MyEclipse指定project为准
MyEclipse指定project
1.Run As->2 Ant Build...->Targets
2.也Run As->2 Ant Build...->Main->Arguments写上 -verbose clean(相当于在控制台写上ant -verbose clean)
如果用以上两种方式指定的project跟构建文件的default project一致的话,相当于没有指定
如果以上两种方式指定的project不同,则表示同时指定两个project,先执行第二种方式指定的project,后执行第一种方式指定的project
第一种方式指定比较方便,直接点钩就行,但推荐使用第二种方式,因为可以加上诸如-verbose之类的参数,输出更多的信息,这是第一种方式做不到的
当然也可以在第二种方式写上-verbose,不写project,用第一种方式写上project
D:\Workspaces\AntTest\src>ant -verbose clean
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Trying the default build file: build.xml
Buildfile: D:\Workspaces\AntTest\src\build.xml
Detected Java version: 1.6 in: C:\Program Files\Java\jre6
Detected OS: Windows 7
parsing buildfile D:\Workspaces\AntTest\src\build.xml with URI = file:/D:/Workspaces/AntTest/src/build.xml
Project base dir set to: D:\Workspaces\AntTest
Build sequence for target(s) `clean' is [init, clean]
Complete build sequence is [init, clean, compile, archive, ]
init:
parsing buildfile jar:file:/E:/JavaEE/Data/Ant/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/E:/JavaEE/Data/Ant/a
pache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
[mkdir] Created dir: D:\Workspaces\AntTest\build\classes
[mkdir] Created dir: D:\Workspaces\AntTest\dist
clean:
[delete] Deleting directory D:\Workspaces\AntTest\build
[delete] Deleting directory D:\Workspaces\AntTest\build\classes
[delete] Deleting directory D:\Workspaces\AntTest\build
[delete] Deleting directory D:\Workspaces\AntTest\dist
[delete] Deleting directory D:\Workspaces\AntTest\dist
BUILD SUCCESSFUL
Total time: 0 seconds
-->
mkdir javac jar clean 在控制台或者MyEclipse指定project的,而不是在构建文件<project name="OurProject" default="archive"
最新推荐文章于 2024-05-04 13:00:00 发布