set ANT_HOME=c:\ant
set JAVA_HOME=c:\jdk-1.5.0.05
set PATH=%PATH%;%ANT_HOME%\bin
它有三个属性:项目名字、默认目标、基础目录(所有相对路径均基于它计算)
Attribute | Description | Required |
name | the name of the project. | No |
default | the default target to use when no target is supplied. | No; however, since Ant 1.6.0, every project includes an implicit target that contains any and all top-level tasks and/or types. This target will always be executed as part of the project's initialization, even when Ant is run with the -projecthelp option. |
basedir | the base directory from which all path calculations are done. This attribute might be overridden by setting the "basedir" property beforehand. When this is done, it must be omitted in the project tag. If neither the attribute nor the property have been set, the parent directory of the buildfile will be used. | No |
4、Properties
属性,用于定义构建过程,或者定义一些变量代表某个长字符串。
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
<pathelement path="${classpath}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<pathelement location="classes"/>
</path>
<path id="tests.path" cache="true">
<path refid="base.path"/>
<pathelement location="testclasses"/>
</path>
四、基本使用
ant [options] [target [target2 [target3] ...]]
Options:
-help, -h print this message
-projecthelp, -p print project help information
-version print the version information and exit
-diagnostics print information that might be helpful to
diagnose or report problems.
-quiet, -q be extra quiet
-verbose, -v be extra verbose
-debug, -d print debugging information
-emacs, -e produce logging information without adornments
-lib <path> specifies a path to search for jars and classes
-logfile <file> use given file for log
-l <file> ''
-logger <classname> the class which is to perform logging
-listener <classname> add an instance of class as a project listener
-noinput do not allow interactive input
-buildfile <file> use given buildfile
-file <file> ''
-f <file> ''
-D<property>=<value> use value for given property
-keep-going, -k execute all targets that do not depend
on failed target(s)
-propertyfile <name> load all properties from file with -D
properties taking precedence
-inputhandler <class> the class which will handle input requests
-find <file> (s)earch for buildfile towards the root of
-s <file> the filesystem and use it
-nice number A niceness value for the main thread:
1 (lowest) to 10 (highest); 5 is the default
-nouserlib Run ant without using the jar files from
${user.home}/.ant/lib
-noclasspath Run ant without using CLASSPATH
-autoproxy Java1.5+: use the OS proxy settings
-main <class> override Ant's normal entry point
{
int a = 0;
int b = a * 10;
//return 0;
}
PC-lint for C/C++ (NT) Vers. 8.00w, Copyright Gimpel Software 1985-2007
--- Module: main.c (C)
_
}
main.c 7 Info 783: Line does not end with new-line
main.c 7 Warning 529: Symbol 'b' (line 5) not subsequently referenced
main.c 5 Info 830: Location cited in prior message
<project name="MyProject" default="dist" basedir=".">
<target name="dist">
<tstamp/>
<exec dir="." executable="lint-nt" os="${os.name}" failonerror="true">
<arg value="main.c"/>
</exec>
</target>
</project>
Buildfile: D:\Tools\apache-ant-1.8.0-bin\test_jelly\lint\build.xml
dist:
[exec] PC-lint for C/C++ (NT) Vers. 8.00w, Copyright Gimpel Software 1985-2
007
[exec]
[exec] --- Module: main.c (C)
[exec] _
[exec] }
[exec]
[exec] main.c 7 Info 783: Line does not end with new-line
[exec] main.c 7 Warning 529: Symbol 'b' (line 5) not subsequently referen
ced
[exec] main.c 5 Info 830: Location cited in prior message
BUILD FAILED
D:\Tools\apache-ant-1.8.0-bin\test_jelly\lint\build.xml:6: exec returned: 3
Total time: 1 second
Apache Ant version 1.8.0 compiled on February 1 2010
Trying the default build file: build.xml
Buildfile: D:\Tools\apache-ant-1.8.0-bin\test_jelly\lint\build.xml
Detected Java version: 1.6 in: C:\Program Files\Java\jdk1.6.0_18\jre
Detected OS: Windows 7
parsing buildfile D:\Tools\apache-ant-1.8.0-bin\test_jelly\lint\build.xml with U
RI = file:/D:/Tools/apache-ant-1.8.0-bin/test_jelly/lint/build.xml
Project base dir set to: D:\Tools\apache-ant-1.8.0-bin\test_jelly\lint
Build sequence for target(s) `dist' is [dist]
Complete build sequence is [dist, ]
dist:
parsing buildfile jar:file:/D:/Tools/apache-ant-1.8.0-bin/lib/ant.jar!/org/apach
e/tools/ant/antlib.xml with URI = jar:file:/D:/Tools/apache-ant-1.8.0-bin/lib/an
t.jar!/org/apache/tools/ant/antlib.xml from a zip file
[exec] Current OS is Windows 7
[exec] Executing 'lint-nt' with arguments:
[exec] 'files.lnt'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
[exec] PC-lint for C/C++ (NT) Vers. 8.00w, Copyright Gimpel Software 1985-2
007
[exec]
[exec] --- Module: main.c (C)
[exec] _
[exec] }
[exec]
[exec] main.c 7 Info 783: Line does not end with new-line
[exec] main.c 7 Warning 529: Symbol 'b' (line 5) not subsequently referen
ced
[exec] main.c 5 Info 830: Location cited in prior message
BUILD FAILED
D:\Tools\apache-ant-1.8.0-bin\test_jelly\lint\build.xml:4: exec returned: 3
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:650)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:676)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:502)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a: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:1360)
at org.apache.tools.ant.Project.executeTarget(Project.java:1329)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1212)
at org.apache.tools.ant.Main.runBuild(Main.java:801)
at org.apache.tools.ant.Main.startAnt(Main.java:218)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 1 second