text replace in xml using ant
I want to change the version number in a xml file using ant. I tried ant's replace task but i开发者_如何学运维t's not working.
The xml file I have looks like this.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org<br>/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz</groupId>
<artifactId>proj</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
You can use copy task. http://ant.apache.org/manual/Tasks/copy.html
abc.template.xml:
<abc version="@VERSION@">
<item name="xxxxx"/>
</abc>
ant_script:
<copy file="abc.template.xml"
tofile="abc.xml"
filtering="yes" overwrite="yes">
<filterset>
<filter token="VERSION" value="1.0"/>
</filterset>
</copy>
I am not sure, but it appears your problem is caused by wrong file or wrong syntax.
I have below content in my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>@VERSION</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
</project>
See below my build.xml
<project name="Test" default="replaceContent" basedir=".">
<target name="replaceContent">
<replace file="src/pom.xml" token="@VERSION" value="5.0.0.0"/>
</target>
</project>
Now If i run $ ant replaceContent, it replace my token @VERSION with whatever i specify in build file as 'value'. So after successful execution, <modelVersion>
value in pom.xml will change to 5.0.0.0
Next time when you post any question, also mention details of error.
精彩评论