ant 打包参考build.xml文件

<project basedir="." default="antwar" name="DTETS">
	<target name="prod" description="设置生产环境变量">
		<copy file="${basedir}/resources/application.properties.prod" tofile="${basedir}/resources/application.properties" overwrite="false"/>
		<copy file="${basedir}/resources/LDAPConfig.xml.prod" tofile="${basedir}/resources/LDAPConfig.xml" overwrite="false"/>
		<copy file="${basedir}/resources/MailConfig.xml.prod" tofile="${basedir}/resources/MailConfig.xml" overwrite="false"/>
	</target>
	
	<target name="qa" description="设置QA环境变量">
		<copy file="${basedir}/resources/application.properties.qa" tofile="${basedir}/resources/application.properties" overwrite="false"/>
		<copy file="${basedir}/resources/LDAPConfig.xml.qa" tofile="${basedir}/resources/LDAPConfig.xml" overwrite="false"/>
		<copy file="${basedir}/resources/MailConfig.xml.qa" tofile="${basedir}/resources/MailConfig.xml" overwrite="false"/>
	</target>
	
	<target name="init" description="设置初始化打war包需要的路径变量 ">
		<property name="name" value="DTETS" />
		<property name="src" value="${basedir}/src" />
		<property name="config" value="${basedir}/resources" />
		<property name="lib" value="${basedir}/webapp/WEB-INF/lib" />		
		<property name="webapp" value="${basedir}/webapp" />
		
		<property name="build.src" value="${basedir}/AntBuild/TEST/src" />
		<property name="build.dest" value="${basedir}/AntBuild/TEST/WEB-INF/classes" />
		<property name="build.lib" value="${basedir}/AntBuild/TEST/WEB-INF/lib" />
		<property name="buildwar.dest" value="${basedir}/AntBuild/TEST" />
		<property name="war.dest" value="${basedir}/deploy" />

		<tstamp>
			<format property="TODAY" pattern="yyyy-MM-dd_hhmmss" locale="en"/>
		</tstamp>

		<path id="classpath">
			<fileset dir="${build.lib}">
				<include name="**/*.jar" />
			</fileset>
			<fileset dir="${basedir}/buildlib" includes="**/*.jar" />
		</path>
	</target>

	<target name="prepare" depends="init" description="创建打包需要的路径,拷贝java源文件到打包路径下">
		<delete dir="${basedir}/AntBuild" />
		
		<mkdir dir="${build.src}" />
		<mkdir dir="${build.dest}" />
		<mkdir dir="${buildwar.dest}" />
		<mkdir dir="${war.dest}" />
		<mkdir dir="${build.lib}" />
		
		<copy todir="${build.src}">
			<fileset dir="${src}">
				<exclude name="**/*.xml" />
			</fileset>
		</copy>
		
		<copy todir="${build.lib}">
			<fileset dir="${lib}" />
		</copy>

		<copy todir="${buildwar.dest}">
			<fileset dir="${webapp}">
				<exclude name="**/*.class" />
				<exclude name="**/*.jar" />
			</fileset>
		</copy>
	</target>


	<!--
	     编译选项
	    -->

	<patternset id="compiler.resources">
		<exclude name="**/?*.qa" />
		<exclude name="**/?*.prod" />
	</patternset>

	<!--
	      编译Java文件并复制资源文件
	    -->
	<target name="compile" depends="prepare" description="编译Java文件并复制资源文件">
																										   
		<javac destdir="${build.dest}" fork="true" debug="on" source="1.6" encoding="UTF-8" includeantruntime="on"  executable="D:\Java\IBM_JDK1.6\bin\javac">
			<classpath refid="classpath" />																					 
			<src path="${src}" />
		</javac>

		<copy todir="${build.dest}">
			<fileset dir="${config}">
				<patternset refid="compiler.resources" />
			</fileset>
			<fileset dir="${src}">
				<exclude name="**/?*.java" />
			</fileset>
		</copy>
	</target>

	<target name="antwar" depends="prod,compile" description="打war包">
		<war warfile="${war.dest}/${name}_prod_${TODAY}.war" webxml="${buildwar.dest}/WEB-INF/web.xml">
			<fileset dir="${buildwar.dest}" />
		</war>
	</target>
	
	<target name="antwar_qa" depends="qa,compile" description="打war包">
		<war warfile="${war.dest}/${name}_qa_${TODAY}.war" webxml="${buildwar.dest}/WEB-INF/web.xml">
			<fileset dir="${buildwar.dest}" />
		</war>
	</target>

</project>

 

展开阅读全文

没有更多推荐了,返回首页