ant property 总结

详见:http://ant.apache.org/manual/index.html

1.特点

大小写敏感;

不可改变,先到先得,谁先设定,之后的都不能改变。

如下的build.xml

 

 <project name="MbopManageWeb" default="release" basedir="..">
	 
  <property name="releasedir" value="D:\anttest\mbop" />
	 <property name="releasedir" value="D:\anttest\manage" />
   <echo>打包后发布路径:${releasedir}</echo>
	
	<target name="release">
			<delete dir="${releasedir}" />
			<mkdir dir="${releasedir}" />
		</target>
</project>

 

 执行后控制台的打印信息如下所示:

 

Buildfile: D:\myworkspace\MbopManageWeb\build\build_test.xml
     [echo] 打包后发布路径:D:\anttest\mbop
release:
   [delete] Deleting directory D:\anttest\mbop
    [mkdir] Created dir: D:\anttest\mbop
BUILD SUCCESSFUL
Total time: 172 milliseconds

“D:\anttest\mbop”,说明它的值一旦设定后,就无法再修改了。


2、property类似于变量,可以提供给build.xml中的其他元素使用 


<property>元素可以跟很多种属性,各属性如下所示:

AttributeDescriptionRequired
namethe name of the property to set.No
valuethe value of the property.One of these or nested text, when using the name attribute
locationSets the property to the absolute filename of the given file. If the value of this attribute is an absolute path, it is left unchanged (with / and \ characters converted to the current platforms conventions). Otherwise it is taken as a path relative to the project's basedir and expanded.
refid Reference to an object defined elsewhere. Only yields reasonable results for references toPATH like structures or properties.
resourcethe name of the classpath resource containing properties settings in properties file format.One of these, whennot using the name attribute
filethe location of the properties file to load.
urla url containing properties-format settings.
environmentthe prefix to use when retrieving environment variables. Thus if you specify environment="myenv" you will be able to access OS-specific environment variables via property names "myenv.PATH" or "myenv.TERM". Note that if you supply a property name with a final "." it will not be doubled; i.e. environment="myenv." will still allow access of environment variables through "myenv.PATH" and "myenv.TERM". This functionality is currently only implemented on select platforms. Feel free to send patches to increase the number of platforms on which this functionality is supported ;).
Note also that properties are case-sensitive, even if the environment variables on your operating system are not; e.g. Windows 2000's system path variable is set to an Ant property named "env.Path" rather than "env.PATH".
classpaththe classpath to use when looking up a resource.No
classpathrefthe classpath to use when looking up a resource, given as reference to a <path> defined elsewhere..No
prefixPrefix to apply to properties loaded using fileresource, or url. A "." is appended to the prefix if not specified.No
prefixValuesWhether to apply the prefix when expanding the right hand side of properties loaded usingfileresource, or urlSince Ant 1.8.2 No (default=false)
relativeIf set to true the relative path to basedir is set. Since Ant 1.8.0 No (default=false)
basedirThe basedir to calculate the relative path from. Since Ant 1.8.0 No (default=${basedir})

 

 

3.   7种设置方式

1)、设置name和value属性值,比如:<property name="srcdir" value="${basedir}/src"/>

2)、设置name和refid属性值,比如:<property name="srcpath" refid="dao.compile.classpath"/>,其中dao.compile.classpath在别的地方定义。

3)、设置name和location属性值,比如:<property name="srcdir" location="src"/>,即将srcdir的值设置为:当前项目根目录的/src目录。

4)、设置file属性值,比如:<property file="build.properties"/>, 导入build.properties属性文件中的属性值

5)、设置resource属性值,比如:<propety resource="build.properties"/>,导入build.properties属性文件中的属性值

6)、设置url属性值,比如:<property url="http://www.mysite.com/bla/props/foo.properties"/>,导入http://www.mysite.com/bla/props/foo.properties属性文件中的属性值。

7)、设置环境变量,比如:<property environment="env"/>,设置系统的环境变量为前缀env.

     <property name="tomcat.home" value="${env.CATALINA_HOME}"/> 将系统的tomcat安装目录设置到tomcat.home属性中。


4.内置属性

Ant’s built-in properties:

basedir

The absolute path of the project’s basedir.

ant.file

The absolute path of the buildfile.

ant.version

The version of Ant.

ant.project.name

The name of the project that is currently executing.

ant.project.default-target

The name of the currently executing project’s default target.

ant.project.invoked-targets

A comma separated list of the targets that have been specified on the command line when invoking the current.

ant.java.version

The JVM version Ant detected.

ant.core.lib

The absolute path of the ant.jar file.


 

 

内置属性basedir

 -- 不需要定义就可以直接使用,${basedir},得到当前工程的绝对路径

 -- 当在<project>标签的basedir属性中指定basedir时,之后工程中出现的所有相对路径都是相对于这个basedir所指向的路径,且${basedir}的值也将变为<project>标签中的basedir属性所指定的值。


5.  只有在声明了property之后,才能引用它,否则的话就会视为普通的字符串,比如 、

 

 

<mkdir dir="${build.classes.dir}" />  

 如果这个时候还没有声明build.classes.dir,那么就会视为${build.classes.dir}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值