简体   繁体   English

将Echo Ant属性复制到文件

[英]Echo Ant property to a File

I am having problems echoing a property to a file. 我在将属性回显到文件时遇到问题。 I am pretty sure there is some misspelling that i can not spot right now or some concept i am missing. 我很确定我现在无法发现某些拼写错误,或者我缺少一些概念。 The target is: 目标是:

<target name="war" depends="build">
    <propertyfile file="project-version.properties">
        <entry key="build.version" type="int" operation="+" value="1"/>
    </propertyfile>
    <echo file="WebContent/version.txt">${major.version}.${minor.version}.${build.version}</echo>
    <war destfile="dist/system.war" webxml="WebContent/WEB-INF/web.xml">
        <fileset dir="WebContent"/>
        <classes dir="target/classes"/>
    </war>
</target>

It properly updates the key build.version from file project-version.properties: 它会从文件project-version.properties中正确更新密钥build.version:

#Tue Mar 29 19:14:18 BRT 2011
build.number=3
major.version=1
build.version=16
minor.version=0

But the output version.txt is: 但是输出的version.txt是:

${major.version}.${minor.version}.${build.version}

The propertyfile task does not load the properties into the script and this is why when you try to output them, ant can't expand them to any value. propertyfile任务不会将属性加载到脚本中,这就是为什么当您尝试输出它们时,ant无法将它们扩展为任何值的原因。

To solve it, you could just load the project-version.properties file after the updating it. 为了解决这个问题,您可以在更新后加载project-version.properties文件。

<target name="war" depends="build">
   <propertyfile file="project-version.properties">
       <entry key="build.version" type="int" operation="+" value="1"/>
   </propertyfile>
   <property file="project-version.properties" />
   <echo file="WebContent/version.txt">${major.version}.${minor.version}.${build.version}</echo>
   <war destfile="dist/system.war" webxml="WebContent/WEB-INF/web.xml">
       <fileset dir="WebContent"/>
       <classes dir="target/classes"/>
   </war>
</target>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM