开发者

Echo Ant property to a File

开发者 https://www.devze.com 2023-02-20 11:34 出处:网络
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:

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:

#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:

${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.

To solve it, you could just load the project-version.properties file after the updating it.

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号