Maven Ant 中截取字符串

在ant中,无法实现常见的字符串操作,比如截取、替换。我们可以借助ant-contrib中实现字符串的截取、替换.

下面的例子是在maven中运行ant,ant中来做字符串截取,我们从一个txt中读取字符串,并使用回车换行进行字符串的分割。


<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
	<version>1.7</version>
	<executions>
		<execution>
			<id>generate-installer</id>
			<phase>compile</phase>
			<configuration>
			    <tasks>
			        <loadfile property="strfile" srcFile="c:/str.txt" encoding="GBK"/>									    
				<taskdef resource="net/sf/antcontrib/antlib.xml"/>
				<for list="${strfile}" delimiter="&#xD;&#xA;" param = "val">
                                    <sequential><echo message = "val = @{val}"/></sequential>
				</for>
			    </tasks>
			</configuration>
			<goals>
				<goal>run</goal>
			</goals>
		</execution>
	</executions>
	<dependencies>
		<dependency>
			<groupId>ant-contrib</groupId>
			<artifactId>ant-contrib</artifactId>
			<version>1.0b3</version>
			<exclusions>
				<exclusion>
					<groupId>ant</groupId>
					<artifactId>ant</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>
</plugin>


感谢参考的帖子:http://luhantu.iteye.com/blog/2069978


你可能感兴趣的:(Maven Ant 中截取字符串)