执行ant构建文件过后,没有修改任何相关的文件,第二遍执行ant,这时ant会提示任务已经完成的任务不再执行,记住这是任务级别的,这种情况包括在控制台上指定两个project

本文介绍了一个使用Ant构建工具的示例项目,详细解释了如何通过编写Ant构建脚本来实现项目的初始化、编译、打包和清理等操作。同时,还探讨了Ant如何智能地跳过已完成的任务,以提高构建效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?xml version="1.0" encoding="UTF-8"?>

<!-- mkdir javac jar clean 执行ant构建文件过后,没有修改任何相关的文件,第二遍执行ant,这时ant会提示任务已经完成的任务不再执行,记住这是任务级别的,这种情况包括在控制台上指定两个project-->
<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>

<!--
执行ant构建文件过后,没有修改任何相关的文件,第二遍执行ant,这时ant会提示任务已经完成的任务不再执行,
比如任务是创建文件夹,可是文件夹已经创建了(可能是第一次执行构建文件时创建的,也有可能是手工创建的))
[mkdir] Skipping D:\Workspaces\AntTest\build\classes because it already exists.
记住这是任务级别的

还有,比如,在控制台上指定两个project,D:\Workspaces\AntTest\src>ant init clean -verbose
可是执行project clean是仍会去执行project init,此时ant检查init中的任务已经执行过了,就不再执行其中的任务了,但是project init
还是会去执行,只不过没去执行其中的任务

D:\Workspaces\AntTest\src>ant init clean -verbose
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) `init' is [init]
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
Build sequence for target(s) `clean' is [init, clean]
Complete build sequence is [init, clean, compile, archive, ]

init:
    [mkdir] Skipping D:\Workspaces\AntTest\build\classes because it already exists.
    [mkdir] Skipping D:\Workspaces\AntTest\dist because it already exists.

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
-->


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值