欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ant输出信息

程序员文章站 2022-05-23 21:03:38
...

 

Ant文件

<?xml version="1.0" encoding="utf8"?>
<project name="echoMsg" basedir="." default="showProp">
	<description>echo all kinds of info</description>
	
	<!--定义要输入的内容 -->
	<property name="username" value="admin"/>
	<property name="password" value="123"/>
	<property name="url" value="jdbc:mysql://localhost:8080/demo" />
	<property name="driver" value="com.mysql.jdbc.Driver"/>
	<property name="targetFile" value="myprop.properties"/>
	
	
	<target name="init">
			<echo message="------ init target run ---------" />
			<delete file="${targetFile}"/>
			<echo message="------ delete file success ---------" />
	</target>
	
	<target name="echoSimpMsg" depends="init">
			<echo message="------ echoSimpMsg target run ---------" />
			<echo message="echo a simple Msg" />
	</target>
	
	<!-- 将配置信息输出到文件 -->
	<target name="echoMsgToFile" depends="echoSimpMsg">
			<echo message="------ echoMsgToFile target run ---------" />
			<!-- 使用 ${line.seperator}作为换行符 -->
			<echo file="${targetFile}" message="username1=${username}${line.separator}password1=${password}" />
			<echo message="------ echoMsgToFile target finished ---------" />
	</target>
	
	<!-- 将配置信息追加到文件 -->
	<target name="appendMsgToFile" depends="echoMsgToFile">
			<echo message="------ appendMsgToFile target run ---------" />
			<echo file="${targetFile}" message="${line.separator}url1=${url}${line.separator}driver1=${driver}" append="true"/>
			<echo message="------ appendMsgToFile target finished ---------" />
	</target>
	
	<!-- 从输出的文件中读取配置信息-->
	<target name="showProp" depends="appendMsgToFile">
			<!-- 使用局部的property才可以显示,不能放在上面 -->
			<property file="${targetFile}"/>
			<echo message="------ appendMsgToFile target run ---------" />
			<echo message="username1=${username1}"/>
			<echo message="password1=${password1}"/>
			<echo message="url1=${url1}"/>
			<echo message="driver1=${driver1}"/>
			<echo message="------ target over ---------" />
	</target>
</project>