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
-
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
分享到:
相关推荐
【Ganeti安装指南】 Ganeti是一款专为Linux系统设计的虚拟化管理工具,它支持基于XEN或KVM的虚拟化技术。本指南旨在详细介绍如何安装和配置Ganeti,使其能够在集群环境中有效管理和运行虚拟实例。...
### Apache Ant 教程知识点概览 #### 一、引言与背景介绍 Apache Ant 是一个用于自动化构建过程的强大工具,特别适用于 Java 项目。它能够显著减少在大型项目中的手动构建工作,如编译、链接和测试等,从而极大地...
【Ant 知识点详解】 Ant 是一个基于 Java 的构建工具,主要负责自动化软件构建过程,如编译、打包、测试等。它起源于开发者对于传统构建工具(如 make、nmake、jam)在跨平台性和灵活性上的不满。Ant 的设计理念是...
"Ant+Tutorial.doc"可能深入到Ant的高级特性,包括使用条件语句(if/else)、属性文件、通配符选择器、宏定义(macrodef)以及自定义任务。通过属性文件,可以外部化配置信息,使构建更具灵活性。宏定义则允许用户...
在学习过程中,提供的`first-ejb3-ant-tutorial-en.pdf`文档将详细解释每个步骤,而`first-ejb3-ant-tutorial.zip`则包含了源代码和相关资源,供读者实际操作练习。 总之,这个教程旨在帮助开发者快速理解和掌握EJB...
16.1.Installation of ANT 16.2.What is ANT 16.3.Configuration of ANT 16.4.Usage of ANT 17.Conclusions 18.Epilogue: Technical Background about this Document 19.About the Author
Tutorial Master是一个编辑器扩展,允许您创建您的游戏互动教程惊人的快速和容易! Tutorial Master2 已经建立了从地面到成为最好的教程制作解决方案之一!教导新玩家(以及潜在用户)如何以你所希望的方式玩游戏! 用户...
operating_system_tutorial.pdf operating_system_tutorial.pdf operating_system_tutorial.pdf operating_system_tutorial.pdf operating_system_tutorial.pdf operating_system_tutorial.pdf operating_system_...
Sun权威教程--《J2EE Tutorial中文版》 作者:Stephanie Bodoff,Dale Green,Kim Haase,Eric Jendrock,Monica Pawlan,Beth Stearns 翻译参与人员:sharetop,worldheart,zhaoy,bruce等 出版商:铁道出版社...
FLUENT 2020R2 tutorial guide PDF及案例源文件 1.What’s In This Manual The ANSYS Fluent Tutorial Guide contains a number of tutorials that teach you how to use ANSYS Flu- ent to solve different types ...
tutorial代码
java tutorialjava tutorial.chm
标题为“Gradle Tutorial”的文档是一份关于Gradle构建工具的英文教程,介绍了Gradle的版本信息、实现方式、核心概念以及如何快速上手。文档指出,Gradle是类似于Maven和Ant的构建工具,它目前正开始被更广泛地采用...
《EDEM教程1 - 传送带》是一份官方的学习资料,专为仿真爱好者设计,旨在帮助他们理解和掌握EDEM软件的使用。EDEM(Eulerian Discrete Element Method)是一种基于离散元方法的颗粒流体动力学软件,广泛应用于各种...
XML Tutorial Schema Tutorial DTD Tutorial DOM Tutorial CSS2 Tutorial
Tutorial ENGLISH
《Ruby on Rails Tutorial》中文版(原书第2版,涵盖 Rails 4) Ruby 是一门很美的计算机语言,其设计原则就是“让编程人员快乐”。David Heinemeier Hansson 就是看重了这一点,才在开发 Rails 框架时选择了 Ruby...
Ansys Fluent Tutorial Guide 2022 R1官方示例(全套官方案例): 包括FLUENT模块所有官方案例三维示例网格文件(31个),还包括帮助文档PDF文件Ansys_Fluent_Tutorial_Guide_2022_R1.pdf,学习FLUENT各个官方案例的...
Understanding .NET - A Tutorial and Analysis Understanding .NET - A Tutorial and Analysis Understanding .NET - A Tutorial and Analysis