现在的位置: 首页 > 综合 > 正文

ant的property使用

2011年03月15日 ⁄ 综合 ⁄ 共 3274字 ⁄ 字号 评论关闭

 

* Ant中可以自定义属性,例如 <property name="var1" value="value1"/>

 

* 也可以使用Java的系统属性,例如:

 java.runtime.name = Java(TM) 2 Runtime Environment, Standard Edition
 sun.boot.library.path = C:/j2sdk1.4.2_09/jre/bin
 java.vm.version = 1.4.2_09-b05
 java.vm.vendor = Sun Microsystems Inc.
 java.vendor.url = http://java.sun.com/
 path.separator = ;
 java.vm.name = Java HotSpot(TM) Client VM
 file.encoding.pkg = sun.io
 user.country = CN
 sun.os.patch.level = Service Pack 2
 java.vm.specification.name = Java Virtual Machine Specification
 user.dir = E:/eclipse/testDemo
 java.runtime.version = 1.4.2_09-b05
 java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
 java.endorsed.dirs = C:/j2sdk1.4.2_09/jre/lib/endorsed
 os.arch = x86
 java.io.tmpdir = C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/
 line.separator =
 java.vm.specification.vendor = Sun Microsystems Inc.
 user.variant =
 os.name = Windows XP
 sun.java2d.fontpath =
 java.library.path = C:/j2sdk1.4.2_09/bin;.;C:/WINDOWS/system32;C:/WINDOWS;C:/j2sdk1.4.2_09/bin;d:/oracle/ora92/bin;C:/Program Files/Oracle/jre/1.1.8/bin;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;D:/MySQL/MySQL Server 4.1/bin;d:/Program Files/IDM Computer Solutions/UltraEdit-32
 java.specification.name = Java Platform API Specification
 java.class.version = 48.0
 java.util.prefs.PreferencesFactory = java.util.prefs.WindowsPreferencesFactory
 os.version = 5.1
 user.home = C:/Documents and Settings/Administrator
 user.timezone =
 java.awt.printerjob = sun.awt.windows.WPrinterJob
 file.encoding = GBK
 java.specification.version = 1.4
 java.class.path = E:/eclipse/testDemo/bin;E:/eclipse/lucene-1.4.3/lucene-2.0.0/lucene- 2.0.0/lucene-core-2.0.0.jar;E:/Library/commons/commons-io-1.1.jar;E: /Library/commons/commons-net-1.1.0.jar;F:/everyday/6月/15/je-analysis- 1[1].2.2.jar;E:/Library/junit/junit.jar
 user.name = Cral
 java.vm.specification.version = 1.0
 java.home = C:/j2sdk1.4.2_09/jre
 sun.arch.data.model = 32
 user.language = zh
 java.specification.vendor = Sun Microsystems Inc.
 awt.toolkit = sun.awt.windows.WToolkit
 java.vm.info = mixed mode
 java.version = 1.4.2_09
 java.ext.dirs = C:/j2sdk1.4.2_09/jre/lib/ext
 sun.boot.class.path = C:/j2sdk1.4.2_09/jre/lib/rt.jar;C:/j2sdk1.4.2_09/jre/lib/i18n.jar;C:/j2sdk1.4.2_09/jre/lib/sunrsasign.jar;C:/j2sdk1.4.2_09/jre/lib/jsse.jar;C:/j2sdk1.4.2_09/jre/lib/jce.jar;C:/j2sdk1.4.2_09/jre/lib/charsets.jar;C:/j2sdk1.4.2_09/jre/classes
 java.vendor = Sun Microsystems Inc.
 file.separator = /
 java.vendor.url.bug = http://java.sun.com/cgi-bin/bugreport.cgi
 sun.io.unicode.encoding = UnicodeLittle
 sun.cpu.endian = little
 sun.cpu.isalist = pentium i486 i386

 

* 还可以使用Ant内置的属性,例如:

basedir project基目录的绝对路径 (与<project>的basedir属性一样)。

ant.file buildfile的绝对路径。

ant.version Ant的版本。

ant.project.name 当前执行的project的名字;由<project>的name属性设定.

ant.java.version Ant检测到的JVM的版本;目前的值有"1.1", "1.2", "1.3" and "1.4".

 

 

1 使用-Dvar=value来在运行时指定或修改property的值

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="test" name="testproject">
  
<property name="var1" value="value1"/>
  
<property name="var2" value="value2"/>
  
<target name="test" description="test property overwrite">
    
<echo message="var1=${var1}"/>
    
<echo message="var2=${var2}"/>
  
</target>
</project>

 

运行ant为:

test:
     [echo] var1=value1
     [echo] var2=value2

运行ant -Dvar1=value1new为:

test:
     [echo] var1=value1new
     [echo] var2=value2

 

2Ant中使用系统的环境变量

<target name="printinfo">
  <property environment="env" />
  <echo message="${env.BUILD_TAG}"/>
</target>

 

3

 

完!

 

抱歉!评论已关闭.