忽略属性的覆盖 [英] Override ignored for property

查看:22
本文介绍了忽略属性的覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Content of Build.xml File


<?xml version="1.0"?>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="ant-contrib-0.6.jar"/>
<taskdef classpath="orangevolt-ant-tasks-1.3.2.jar" resource="com/orangevolt/tools/ant/taskdefs.properties"/>               
<project name="initinstaller" default="all" basedir="." >       
<target name="configure-server-types-module">       
    <property file="./installation.conf"/>  
    <echo message="${client.server.types}"/>
    <if>
        <not>               
            <contains string="${client.server.types}" substring="tomcat" />
        </not>
    <then>
        <replaceregexp file="./installation.conf"
                match="client.server.types=(.*)" 
                replace="client.server.types=\1tomcat,"
                byline="true">
        </replaceregexp>
    </then>
    </if>       
</target>

<target name="all" depends="configure-server-types-module">     
    <property file="./installation.conf"/>  
    <echo message="${client.server.types}"/>
    <if>
        <not>               
            <contains string="${client.server.types}" substring="tomcat" />
        </not>
    <then>
        <replaceregexp file="./installation.conf"
                match="client.server.types=(.*)" 
                replace="client.server.types=\1tomcat,"
                byline="true">
        </replaceregexp>
    </then>
    </if>       
</target>

Content of installation.conf : client.server.types=jboss,

详细输出:

Apache Ant version 1.8.1 compiled on April 30 2010
Trying the default build file: build.xml
Buildfile: D:\testing\build.xml
Detected Java version: 1.6 in: C:\Program Files\Java\jdk1.6.0_21\jre
Detected OS: Windows XP
parsing buildfile D:\testing\build.xml with URI = file:/D:/testing/build.xml
Project base dir set to: D:\testing
parsing buildfile jar:file:/C:/apache-ant-1.8.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/apache-ant-1.8.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
dropping D:\testing\ant-contrib-0.6.jar from path as it doesn't exist
dropping D:\testing\orangevolt-ant-tasks-1.3.2.jar from path as it doesn't exist
Build sequence for target(s) `all' is [configure-server-types-module, all]
Complete build sequence is [configure-server-types-module, all, ]

configure-server-types-module:

[property] Loading D:\testing\installation.conf

[echo] jboss,

[replaceregexp] Replacing pattern 'client.server.types=(.*)' with 
'client.server.types=\1tomcat,' in 'D:\testing\installation.conf' by line.

[replaceregexp] File has changed; saving the updated file


all:

[property] Loading D:\testing\installation.conf

**Override ignored for property "client.server.types"**

[echo] jboss,

[replaceregexp] Replacing pattern 'client.server.types=(.*)' with 
'client.server.types=\1tomcat,' in 'D:\testing\installation.conf' by line.

[replaceregexp] File has changed; saving the updated file

BUILD SUCCESSFUL

Total time: 0 seconds

==============================================================

我的问题是如何覆盖 ant 属性

my question is that how i can override the ant property

推荐答案

一旦设置了 Ant 属性,其值就无法更改.

Once an Ant property has been set its value cannot be changed.

也许您可以在第一次加载属性文件时使用 任务的 prefix 属性,以便属性具有不同的名称:

Perhaps you could use the prefix attribute of the <property> task when you first load the properties file so that the property has a different name:

<target name="configure-server-types-module">       
  <property file="./installation.conf" prefix="temp."/>  
  <echo message="${temp.client.server.types}"/>
  <if>
    <not>               
      <contains string="${temp.client.server.types}" substring="tomcat" />
    </not>
    <then>
      <replaceregexp file="./installation.conf"
                     match="client.server.types=(.*)" 
                     replace="client.server.types=\1tomcat,"
                     byline="true">
      </replaceregexp>
    </then>
  </if>       
</target>

注意:我还没有测试过.

Note: I haven't tested this.

然后在第二个目标中您仍然可以使用专有名称,因为该属性尚未设置.

Then in the second target you can still use the proper name as that property has not been set yet.

(此解决方案仅适用于安装了第 3 方插件 ANT-contrib-library:ANT contrib 下载)

(this solution only works with 3rd-party plugin ANT-contrib-library installed: ANT contrib Download)

这篇关于忽略属性的覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆