我想使用ant更改xml文件中的版本号。 我尝试过ant的替换任务,但它没有用。
我的xml文件看起来像这样。
<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>
答案 0 :(得分:4)
您可以使用复制任务。 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>
答案 1 :(得分:0)
我不确定,但看起来您的问题是由错误的文件或错误的语法引起的。
我的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>
请参阅下面的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>
现在如果我运行$ ant replaceContent,它将我的令牌@VERSION替换为我在构建文件中指定为'value'的任何内容。因此,成功执行后,pom.xml中的<modelVersion>
值将更改为5.0.0.0
下次发布任何问题时,还请提及错误详情。