从文本文件中检索值并使用 ant 脚本用该值替换另一个文件中的字符串常量 [英] Retrieve value from text file and replace a string constant in another file with that value using ant script
问题描述
我有一个名为 versionInfo.txt 的文件.该文件包含以下文本:Implementation-Version: 7.5.0.1".
I have a file called versionInfo.txt. This file among other things has the following text: "Implementation-Version: 7.5.0.1".
我需要检索版本值并将此版本值复制到 Java 文件中.Java 文件将具有以下变量:
I need to retrieve the version value and copy this version value to a Java file. The Java file will have the following variable:
version = "@version-info@";
我需要用我从第一个文件中检索到的值替换这个@version-info@.我需要将此代码插入使用 ant 脚本编写的现有 build.xml 文件中.
I need to replace this @version-info@ with the value I retrieved from the first file. I need to do plug in this code in an existing build.xml file written using ant script.
推荐答案
像这样创建一个属性文件并将其命名为 build.properties
Create a properties file like this and name it build.properties
version.label=7.5.0.1
然后在你的 build.xml 文件中
Then in your build.xml file
<project basedir=".">
<target name="replace-labels">
<property file="${basedir}/build.properties"/>
<replace
file="${basedir}/myClass.java"
token="@version-info@"
value="${version.label}" />
</target>
</project>
所以你的文件结构应该是这样的
So your file structure should look like
myproject
build.properties
build.xml
myClass.java
然后您可以通过更改到myproject"目录并执行来执行您的 ANT 构建
Then you can execute your ANT build by changing to the "myproject" directory and executing
ant replace-labels
replace
标记将在 myClass.java 文件中查找字符串@version-info@"并将其替换为值7.5.0.1"
The replace
tag will look for the string "@version-info@" in your myClass.java file and replace it with the value "7.5.0.1"
这篇关于从文本文件中检索值并使用 ant 脚本用该值替换另一个文件中的字符串常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!