你的位置:首页 > 软件开发 > Java > Ant :Property

Ant :Property

发布时间:2016-04-19 14:00:42
PropertyAnt 内置的Property系统属性Ant附加的属性自定义PropertyAnt :Property properties是由key-value组成的集合,就是Java中的Properties集合。属性的定义使用的是<property>。通 ...
  •  Property
    • Ant 内置的Property
      • 系统属性
      • Ant附加的属性
    • 自定义Property

Ant :Property

 

 

properties是由key-value组成的集合,就是Java中的Properties集合。属性的定义使用的是<property>。通常情况下,property值一经设置,就不能再改变了。Property是全局范围的properties中的一个元素,所以每个property都是全局的,是可以被任何的target、task使用。

 

Ant内置的属性

系统属性

Ant对Java程序的系统属性做了支持,可以直接的访问系统属性:

<project default="showSystemProperties">

    <target name="showSystemProperties">

       <echo>${java.version}</echo>

       <echo>${java.vendor}</echo>

       <echo>${java.vendor.url}</echo>

       <echo>${java.home}</echo>

       <echo>${java.vm.specification.version}</echo>

       <echo>${java.vm.specification.vendor}</echo>

       <echo>${java.vm.specification.name}</echo>

       <echo>${java.vm.version}</echo>

       <echo>${java.vm.vendor}</echo>

       <echo>${java.vm.name}</echo>

       <echo>${java.specification.version}</echo>

       <echo>${java.specification.vendor}</echo>

       <echo>${java.specification.name}</echo>

       <echo>${java.class.version}</echo>

       <echo>${java.class.path}</echo>

       <echo>${java.library.path}</echo>

       <echo>${java.io.tmpdir}</echo>

       <echo>${java.compiler}</echo>

       <echo>${java.ext.dirs}</echo>

       <echo>${os.name}</echo>

       <echo>${os.arch}</echo>

       <echo>${os.version}</echo>

       <echo>${file.separator}</echo>

       <echo>${path.separator}</echo>

       <echo>${line.separator}</echo>

       <echo>${user.name}</echo>

       <echo>${user.home}</echo>

       <echo>${user.dir}</echo>

    </target>

</project>

 

Ant附加的属性

 

basedir             the absolute path of the project's basedir (as set
                    with the basedir attribute of <project>).
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;
                    it is set in the name attribute of <project>.
ant.project.default-target
                    the name of the currently executing project's
                    default target;  it is set via the default
                    attribute of <project>.
ant.project.invoked-targets
                    a comma separated list of the targets that have
                    been specified on the command line (the IDE,
                    an <ant> task ...) when invoking the current
                    project.
                    This property is set properly when the first target is executed.
                    If you use it in the implicit target (directly
                    under the <project> tag) the list will be
                    empty if no target has been specified while it
                    will contain the project's default target in this
                    case for tasks nested into targets..
ant.java.version    the JVM version Ant detected; currently it can hold
                    the values "1.9", "1.8",
                    "1.7", "1.6", "1.5",
                    "1.4", "1.3" and
                    "1.2".  ant.core.lib the absolute path
                    of the ant.jar file.
ant.home            home directory of Ant
ant.library.dir     the directory that has been used to load Ant's
                    jars from.  In most cases this is ANT_HOME/lib.

 

 

 

 

    <target name="showAntBuildInProperties">

       <echo>${basedir}</echo>

       <echo>${ant.file}</echo>

       <echo>${ant.version}</echo>

       <echo>${ant.project.name}</echo>

       <echo>${ant.project.default-target}</echo>

       <echo>${ant.project.invoked-targets}</echo>

       <echo>${ant.java.version}</echo>

       <echo>${ant.home}</echo>

       <echo>${ant.library.dir}</echo>

    </target>

执行结果:

showAntBuildInProperties:

     [echo] D:\Ant_Test\task

     [echo] D:\Ant_Test\task\build.

     [echo] Apache Ant(TM) version 1.9.4 compiled on April 29 2014

     [echo] ${ant.project.name}

     [echo] showAntBuildInProperties

     [echo] showAntBuildInProperties

     [echo] 1.7

     [echo] E:\Program Files\apache\ant\apache-ant-1.9.4

     [echo] E:\Program Files\apache\ant\apache-ant-1.9.4\lib

 

 

 

 

自定义Property

在build.中可以使用<property>来自定义属性。属性一经设置,将不可改变。

共有7种方式可以设置属性:

·

 

Attribute

Description

Required

name

属性名

No

value

属性值

One of these or nested text, when using the name attribute

location

Sets 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.

resource

the name of the classpath resource containing properties settings in properties file format.

One of these, whennot using the name attribute

file

the location of the properties file to load.

url

a url containing properties-format settings.

environment

the 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 ;).

原标题:Ant :Property

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录