`
shoppingbill
  • 浏览: 58316 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Ant Installation Tutorial

    博客分类:
  • Ant
阅读更多

Learn how to install Ant and compile a simple hello world program.
学习怎样安装Ant和编译一个简单的hello world程序

Ant > Ant Installation
Ant Installation
Ant is free and open source build tool, written in Java, helps in automating the entire build process of a Java development project.
Ant安装
Ant是免费和开源的build工具,用Java编写,有助于Java 项目开发的自动build处理.

 

  • Ant uses XML build files.
  • By default, Ant looks for a build file named build.xml.
  • The build file contains information about how to build a particular project.
  • Each project contains multiple targets like creating directory, compiling source codes.
  • Target can depend on other targets.
  • Targets contain tasks.
  • Behind each task is a Java class that performs the described work
  • Ant 用xml build 文件.
  • 默认情况下,Ant会找一个名字叫build.xml的文件.
  • 这个build文件包含怎样build详细项目有关信息.
  • 每个项目包含多个target像创建目录,编译源码.
  • target可以依赖其他的target.
  • 在每个任务的后面是描述Java class
To install Ant follow the steps given below.
安装Ant步骤如下:
  • Download the latest Ant distribution.
  • Extract it (my location is E:\apache-ant-1.7.1)
  • Set the following system variables
  • ANT_HOME =E:\apache-ant-1.7.1
  • PATH = %ANT_HOME%\bin
  • 下载Ant的最新发布版本
  • 解压(我路径是在E:\apache-ant-1.7.1)
  • 设置以下系统变量
  • ANT_HOME =E:\apache-ant-1.7.1
  • PATH = %ANT_HOME%\bin

      

 

To make sure the installation is proper, go to command prompt and execute the command "ant - version", you will see the installed ant version.
保证你的安装设置是正确的,道命令行下运行"ant -version",你会看到安装的ant版本信息

 




In this example you will see how to compile a java program and compress it into a .jar file using Ant build file. The following listing shows the build.xml file.

在这个例子里你会看到怎么样用Ant构建文件编译Java程序和压缩成.jar文件.Following build.xml列表.

 

 

<?xml version="1.0" ?>
<project name="Hello World" default="compress">
<target name="compile">
<javac srcdir="."/>
<echo> Compilation Complete! </echo>
</target>
<target name="compress" depends="compile">
<jar destfile="HelloWorld.jar" basedir="." includes="*.class" />
<echo> Building .jar file Complete! </echo>
</target>
</project>

 

  • The <project> element is the root element in Ant build files. The name attribute of the project element indicates the project name. Each project element can contain multiple<target> elements.
  • A target represents a single stage in the build process. A build process can have multiple targets. Here we have two targets compile and compress.
  • The default attribute of project element indicates the default target to be executed. Here the default target is compress.
  • When you see the compress target, it in turn depends on the compile target, that is indicated by the depends attribute. So the compile target will be executed first.
  • The compile target has two task elements <javac> and <echo>. The javac task is used to compile the java files. The attribute srcdir="." indicates all the java files in the current directory. Echo task is used to display message on the console.
  • The compress target also performs two tasks, first the <jar> element as the name indicates, is used to build the jar file. The attributes destfile="HelloWorld.jar" , basedir="." andincludes="*.class" indicates all the .class files in the current directory should be compressed into HelloWorld.jar file. Later the echo task is used to display the success message on the console.

To run the build.xml file, open the command prompt, go to the example directory, type the command "ant". You will see the following information.

 

  • 在Ant构建文件里<project>元素是根目录.project 的name属性表示project的名字.每个project元素可以包含多个<target>元素
  • 在构建处理过程中target代表单一的步骤,一个构建处理过程中可以包含多个<target>元素.这里我们有2个<target> compile和compress

 

 

 

  • project元素default属性表示运行默认target.这里默认的target是compress.

 

  • compress target 依赖compile target.那是通过depends属性表示. 所以compile target会先运行.
  • compile target有2个任务元素<javac>和<echo>.javac任务是用来编译java文件.srcdir="."属性表示所有的java文件在当前目录下。echo的任务是在控制台上显示信息
  • compress target也有2个任务,第一<jar>元素就像名字表示的那样,用来构建jar文件.属性destfile="HelloWorld.jar",basedir="."和indcludes="*.class"表示当前目录下的所有.class文件压缩到HelloWorld.jar文件中.下面是echo的任务是显示成功信息在控制台上

运行build.xml文件,打开命令行.到example目录下,敲 "ant" .你会看见如下信息:





You can download the build file here.


Build file :Download

  Project :Download
本文源自:
http://www.vaannila.com/ant/ant-tutorial/ant-tutorial.html

 

1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics