这种情况既不是重复执行ant构建文件,也不是在控制台指定多个project,而是纯粹在构建文件有多个依赖关系

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

<!-- 这种情况既不是重复执行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="clean,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构建文件,也不是在控制台指定多个project,而是纯粹在构建文件有多个依赖关系
执行project archive,会先去执行project compile,执行project compile,会先去执行project clean和project init
,执行project clean会先去执行project init,即是archive->compile->clean init->init,执行project clean后,因为
project init已经被执行过,project init便不再被执行,因此没有创建相应的文件夹,执行project compile时就会出错
记住这里的不执行是project级别的

D:\Workspaces\AntTest\src>ant -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) `archive' is [init, clean, compile, archive]
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

compile:

BUILD FAILED
D:\Workspaces\AntTest\src\build.xml:12: destination directory "D:\Workspaces\AntTest\build\classes" does not exist or is not a directory
        at org.apache.tools.ant.taskdefs.Javac.checkParameters(Javac.java:1093)
        at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:892)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:809)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 0 seconds
-->


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值