ANT教程之四 Ant属性任务

Ant构建文件是用XML编写的,它不迎合声明变量,你在最喜欢的编程语言做的。然而,正如你可能已经想到,它会如果允许Ant声明变量,如项目名称,项目源代码目录等有用

Ant使用属性元素,它允许你指定的属性。这允许属性从一个版本改变为另一个。或者从一个环境到另一个。

默认情况下,Ant提供了可以在构建文件中使用下列预定义的属性

属性 描述
ant.file The full location of the build file.
ant.version The version of the Apache Ant installation.
basedir The basedir of the build, as specified in the basedir attribute of theproject element.
ant.java.version The version of the JDK that is used by Ant.
ant.project.name The name of the project, as specified in the name atrribute of theproject element
ant.project.default-target The default target of the current project
ant.project.invoked-targets Comma separated list of the targets that were invoked in the current project
ant.core.lib The full location of the ant jar file
ant.home The home directory of Ant installation
ant.library.dir The home directory for Ant library files - typically ANT_HOME/lib folder.

Ant也使得系统性能(例如:文件分割符),可用于构建文件。

除了以上所述,用户可以使用属性元素定义附加属性。一个例子介绍如下展示了如何定义一个名为站点名称(sitename)属性:

<?xml version="1.0"?>
<project name="Hello World Project" default="info">
  <property name="sitename" value="www.yiibai.com"/>
   <target name="info">
	  <echo>Apache Ant version is ${ant.version} - You are 
	  at ${sitename} </echo>
   </target>
</project>
上述构建文件运行ant应该产生下面的输出:

C:>ant
Buildfile: C:uild.xml

info:
     [echo] Apache Ant version is Apache Ant(TM) version 1.8.2 
     compiled on December 20 2010 - You are at www.yiibai.com

BUILD SUCCESSFUL
Total time: 0 seconds
C:>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值