ant例子

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. -->
<project basedir="." default="war.staging" name="jrtSubChannel">
	<property name="product.name" value="jrtSubChannel" />
	<property name="debuglevel" value="source,lines,vars" />
	<property name="target" value="1.6" />
	<property name="source" value="1.6" />
	<property environment="env" />
	<property file="build.properties" />
	<buildnumber file="build.num" />
	<property name="full.version" value="${majorVersion}.${minorVersion}.${releaseNumber}.${build.number}" />
	<property name="env.COMPUTERNAME" value="${env.HOSTNAME}" />


	<path id="build.classpath">
		<pathelement location="build/classes" />
	
        <fileset dir="WebContent/WEB-INF/lib" includes="**/*.jar" />
		<fileset dir="doc" includes="**/*.jar" />
	</path>
	<target name="init" depends="clean">
		<mkdir dir="build/classes" />
		<tstamp></tstamp>
		<copy includeemptydirs="false" todir="build/classes">
			<fileset dir="src/" excludes="**/*.launch, **/*.java" />
		</copy>
	</target>
	<target name="clean">
		<delete dir="build/classes" />
		<delete dir="build/WebContent" />
	</target>
	
	

	<target depends="init" name="build">
		<echo message="${ant.project.name}: ${ant.file}" />
		<javac debug="true" encoding="utf-8" debuglevel="${debuglevel}" destdir="build/classes" source="${source}" target="${target}">
			<src path="src/"/>
			<classpath refid="build.classpath" />
		</javac>
	</target>
	<!--时间戳 -->
	  <tstamp prefix="mytime"> 
	        <format property="day" pattern="yyyy-MM-dd"/> 
	        <format property="time" pattern="HH:mm:ss"/> 
	        <format property="dt" pattern="yyyy-MM-dd HH:mm:ss.SSS"/> 
	  	    <format property="date" pattern="yyyyMMddHHmm"/>
	    </tstamp> 
	
	<target name="localwar" depends="build">
		<delete file="build/${product.name}.war"/>
		<copy todir="build/WebContent/">
			<fileset dir="WebContent" includes="**/*" excludes="**/.svn" />
		</copy>
		<copy todir="build/WebContent/WEB-INF/classes">
			<fileset dir="build/classes" excludes="**/.svn" />
		</copy>
		     
				<war warfile="build/${product.name}.war" webxml="WebContent/WEB-INF/web.xml" manifest="MANIFEST.MF">
					<fileset dir="build/WebContent" />
				</war>
		
		<echo>产生war后将编译文件删除</echo>
		<delete dir="build/classes"/>
		<delete dir="build/WebContent"/>
	</target>
	
	<target name="war.staging" depends="build">

		<delete file="build/staging/${product.name}.war" />
		<delete file="build/prod/${product.name}.war" />
		<delete file="MANIFEST.MF" />
		<copy todir="build/WebContent/">
			<fileset dir="WebContent" includes="**/*" excludes="**/.svn" />
		</copy>
		<copy todir="build/WebContent/WEB-INF/classes">
			<fileset dir="build/classes" excludes="**/.svn" />
		</copy>
		<copy overwrite="true" todir="build/WebContent/WEB-INF/classes/" >
			<fileset dir="build/staging"  excludes="**/*.war" />
		</copy>
		<echo>manifestfile</echo> 
		<manifest file="MANIFEST.MF">
			<!--attribute name="Built-By" value="${user.name}" /-->
			<attribute name="jrtRyc-Version" value="${majorVersion}.${minorVersion}.${releaseNumber}.${build.number}" />
		</manifest>
		 
	
		<echo>产生运营war</echo> 
		<copy overwrite="true" todir="build/WebContent/WEB-INF/classes/" >
					<fileset dir="build/staging"  excludes="**/*.war" />
		</copy>
		<war warfile="build/staging/${product.name}.war" webxml="WebContent/WEB-INF/web.xml" manifest="MANIFEST.MF">
			<fileset dir="build/WebContent" />
		</war>

		<!-- 生成运营平台的war包 -->
		<copy overwrite="true" todir="build/WebContent/WEB-INF/classes/" >
			<fileset dir="build/prod"  excludes="**/*.war" />
		</copy>
		<war warfile="build/prod/${product.name}.war" webxml="WebContent/WEB-INF/web.xml" manifest="MANIFEST.MF">
				<fileset dir="build/WebContent" />
		</war>	
		<echo>产生war后将编译文件删除</echo>
		<delete dir="build/classes"/>
		<delete dir="build/WebContent"/>
		<echo>将产生的war包做备份${mytime.date}</echo>
		
		<mkdir dir="build/${mytime.date}"/>
		<copy overwrite="true" todir="build/${mytime.date}">
		  <fileset dir="build/prod" includes="**/*.war"/>
		</copy>
	</target>
		<property name="server-username" value="prelaunch" />
		<property name="server-password" value="[email protected]" />
		<property name="server-address" value="219.148.162.70" />
		<property name="staging-upload-dir" value="tomcat/webapps/" />
	
	
	<property name="tomcat.url" value="http://192.168.0.39:8080/manager"/>
	<property name="tomcat.username" value="tomcat"/>
	<property name="tomcat.password" value="tomcat"/>
	<property name="tomcat.dir" value="D:/apache-tomcat-6.0.32"/>
	<property name="scp-con-staging" value="appusr:[email protected]:/usr/local/apache-tomcat-6.0.32/webapps" />

	  <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask">  
	         <classpath>  
	            <path location="doc/catalina-ant.jar" />  
	        </classpath>  
	   </taskdef>  
	 <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask">  
       <classpath>  
	            <path  location="doc/catalina-ant.jar" />  
	      </classpath>  
	  </taskdef>  
	  <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">  
	       <classpath>  
	           <path location="doc/catalina-ant.jar" />  
	        </classpath>  
    </taskdef> 
	
	<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
	        <classpath>
	            <path location="doc/catalina-ant.jar" />
	        </classpath>
	    </taskdef>

	    <taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
	        <classpath>
	            <path location="doc/catalina-ant.jar" />
	        </classpath>
	    </taskdef>
	
	<target name="stoptomcat" if="already.deployed">
	      <undeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${product.name}" />  
	</target>

	<target name="undeploytomcat" if="already.deployed">
	      <undeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${product.name}" />  
	</target>
	<echo>tomcat_deploy</echo>
	


	<target name="deploytomcat" description="Install application in Tomcat" depends="war.staging">
	       <deploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}"  path="/${product.name}" war="build/staging/${product.name}.war"/>
	</target>
	
	


	<target name="tomcatreload">
        <reload url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${product.name}" />  
	</target>
	<target name="upload.staging">
		<echo>上载staging ${product.name}.war到预上线系统</echo>
		<scp file="../build/staging/${product.name}.war" todir="${scp-con-staging}" trust="true" />
		<property name="scp-con-prod" value="${server-username}:${server-password}@${server-address}:${prod-upload-dir}" />
	</target>
	<target name="upload39">
		<echo>上载staging ${product.name}.war到预上线系统</echo>
		<scp file="build/staging/${product.name}.war" todir="${scp-con-staging}" trust="true" />
		<property name="scp-con-prod" value="${scp-con-staging}" />
	</target>
</project>

你可能感兴趣的:(ant)