工程级错误
ant会加载构建文件的所有元素。它将处理除目标(target)元素意外的所有元素。
如发现一个无法解析的元素 <othersssssss>元素,这将会让构建终止。发现一个错误就会立即中断。
目标级错误
ant不是将<target> 元素嵌套的各个元素全部都加载,而是逐个加载和处理各个元素。当ant到达第二个元素(嵌套在target中的第二个元素),那么会认为第一个元素(嵌套在target中的第一个元素)已经成功。
例子
<?xml version="1.0" encoding="utf-8"?>
<project name="测试" default="all" basedir=".">
<property name="build.dir" value="build" />
<property name="build.classes" value="${build.dir}/classes" />
<property naame="test" value="test value" />
<notareeeeee/>
</project>
运行后提示错误:
D:\source\liyixing\ant>d:\soft\liyixing\ant\apache-ant-1.8.2\bin\ant
Buildfile: D:\source\liyixing\ant\build.xml
BUILD FAILED
D:\source\liyixing\ant\build.xml:5: property doesn't support the "naame" attribu
te
Total time: 0 seconds
build.xml第五行,property元素不存在naame属性。
将naame属性改成name,将提示第二个错误
D:\source\liyixing\ant>d:\soft\liyixing\ant\apache-ant-1.8.2\bin\ant
Buildfile: D:\source\liyixing\ant\build.xml
BUILD FAILED
D:\source\liyixing\ant\build.xml:6: Problem: failed to create task or type notar
eeeeee
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
无法处理notareeeeee元素。
去掉这个元素后
D:\source\liyixing\ant>d:\soft\liyixing\ant\apache-ant-1.8.2\bin\ant
Buildfile: D:\source\liyixing\ant\build.xml
BUILD FAILED
Target "all" does not exist in the project "测试".
Total time: 0 seconds
依然提示错误,因为all目标未定义。
做一下修改
<?xml version="1.0" encoding="utf-8"?>
<project name="测试" default="all" basedir=".">
<property name="build.dir" value="build" />
<property name="build.classes" value="${build.dir}/classes" />
<target name="all" description="所有操作,执行顺序是:clean, compile, jar" depends="clean, compile, jar">
<notareeeeee/>
</target>
<property name="test" value="test value" />
</project>
运行结果
D:\source\liyixing\ant>d:\soft\liyixing\ant\apache-ant-1.8.2\bin\ant
Buildfile: D:\source\liyixing\ant\build.xml
BUILD FAILED
D:\source\liyixing\ant\build.xml:8: property doesn't support the "naame" attribu
te
Total time: 0 seconds
可以看出来它的错误是naame属性不支持。而不是<notareeeeee/>元素无法处理。因为构建的时候target的内部错误只能在执行target才会发现。
ant会加载构建文件的所有元素。它将处理除目标(target)元素意外的所有元素。
如发现一个无法解析的元素 <othersssssss>元素,这将会让构建终止。发现一个错误就会立即中断。
目标级错误
ant不是将<target> 元素嵌套的各个元素全部都加载,而是逐个加载和处理各个元素。当ant到达第二个元素(嵌套在target中的第二个元素),那么会认为第一个元素(嵌套在target中的第一个元素)已经成功。
例子
<?xml version="1.0" encoding="utf-8"?>
<project name="测试" default="all" basedir=".">
<property name="build.dir" value="build" />
<property name="build.classes" value="${build.dir}/classes" />
<property naame="test" value="test value" />
<notareeeeee/>
</project>
运行后提示错误:
D:\source\liyixing\ant>d:\soft\liyixing\ant\apache-ant-1.8.2\bin\ant
Buildfile: D:\source\liyixing\ant\build.xml
BUILD FAILED
D:\source\liyixing\ant\build.xml:5: property doesn't support the "naame" attribu
te
Total time: 0 seconds
build.xml第五行,property元素不存在naame属性。
将naame属性改成name,将提示第二个错误
D:\source\liyixing\ant>d:\soft\liyixing\ant\apache-ant-1.8.2\bin\ant
Buildfile: D:\source\liyixing\ant\build.xml
BUILD FAILED
D:\source\liyixing\ant\build.xml:6: Problem: failed to create task or type notar
eeeeee
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
无法处理notareeeeee元素。
去掉这个元素后
D:\source\liyixing\ant>d:\soft\liyixing\ant\apache-ant-1.8.2\bin\ant
Buildfile: D:\source\liyixing\ant\build.xml
BUILD FAILED
Target "all" does not exist in the project "测试".
Total time: 0 seconds
依然提示错误,因为all目标未定义。
做一下修改
<?xml version="1.0" encoding="utf-8"?>
<project name="测试" default="all" basedir=".">
<property name="build.dir" value="build" />
<property name="build.classes" value="${build.dir}/classes" />
<target name="all" description="所有操作,执行顺序是:clean, compile, jar" depends="clean, compile, jar">
<notareeeeee/>
</target>
<property name="test" value="test value" />
</project>
运行结果
D:\source\liyixing\ant>d:\soft\liyixing\ant\apache-ant-1.8.2\bin\ant
Buildfile: D:\source\liyixing\ant\build.xml
BUILD FAILED
D:\source\liyixing\ant\build.xml:8: property doesn't support the "naame" attribu
te
Total time: 0 seconds
可以看出来它的错误是naame属性不支持。而不是<notareeeeee/>元素无法处理。因为构建的时候target的内部错误只能在执行target才会发现。