lvjian700
5/19/2013 - 9:35 AM

Deploy Java Web Project to FTP

Deploy Java Web Project to FTP

<?xml version="1.0" encoding="utf-8" ?>
<project name="biandan3" default="compile">
  <description>The biandan3 project ant script tools</description>
	<property environment="env"/>
	<property name="basedir" value="." />

	<property name="src.java" value="${basedir}/src/java" />
	<property name="src.groovy" value="${basedir}/src/groovy" />
	<property name="src.res" value="${basedir}/src/resource" />

	<property name="test.java" value="${basedir}/test/java/test" />
	<property name="test.res" value="${basedir}/test/java/resource" />


	<property name="tools.java" value="${basedir}/tools/java" />

	<property name="war.dir" value="${basedir}/war" />
	<property name="war.dest" value="${basedir}/dest" />
	<property name="war.file" value="${basedir}/dest/${ant.project.name}.war" />
	
	<property name="build.dir" value="${war.dir}/WEB-INF" />
	<property name="classes.dir" value="${build.dir}/classes" />
	<property name="lib.dir" value="${build.dir}/lib"/>
	

	<property name="remote.driver" value="\\192.168.1.42\webapps" />

	<property name="ftp.host" value="192.168.1.42"/>
	<property name="ftp.username" value="tomcat"/>
	<property name="ftp.password" value="tomcat"/>
	<property name="ftp.remotedir" value="webapps"/>


	<!-- 设置main函数所在类 -->

	<!-- 定义classpath -->
	<path id="classpath">
		<fileset dir="${lib.dir}" includes="**/*.jar" />
	</path>

	<path id="test-classpath">
		<fileset dir="${lib.dir}" includes="**/*.jar" />
		<fileset dir="${classes.dir}" includes="**/*.class" />
	</path>

	<!-- 创建构建目录,用于存放构建生成的文件 -->
	<target name="init" description="Initialized classpath folder">
		<mkdir dir="${classes.dir}"/>
	</target>

	<!-- 编译 -->
	<target name="compile" depends="init" description="compile project">
		<mkdir dir="${classes.dir}"/>
		<javac srcdir="${src.java};${src.groovy};${src.res};${test.java};${test.res};${tools.java}" destdir="${classes.dir}"
               classpathref="classpath">
			<include name="**/*.java" />
			<compilerarg line="-encoding UTF-8 "/>
		</javac>
		<!-- copy properties file to classpath -->
		<copy todir="${classes.dir}">
			<fileset dir="${src.java}" excludes="**.*.jar" />
		</copy>
		<copy todir="${classes.dir}">
			<fileset dir="${src.groovy}" excludes="**.*.jar" />
		</copy>
		<copy todir="${classes.dir}">
			<fileset dir="${src.res}" excludes="**.*.jar" />
		</copy>
		<copy todir="${classes.dir}">
			<fileset dir="${test.java}" excludes="**.*.jar" />
		</copy>
		<copy todir="${classes.dir}">
			<fileset dir="${test.res}" excludes="**.*.jar" />
		</copy>
		<copy todir="${classes.dir}">
			<fileset dir="${tools.java}" excludes="**.*.jar" />
		</copy>
	</target>
	
	<target name="rmwar" description="clear war file">
		 <delete file="${war.file}"/>
	</target>
	
	<target name="war" depends="rmwar,compile" description="package project to war">
		<war warfile="${war.file}" webxml="${build.dir}/web.xml">
			<lib dir="${build.dir}/lib"/>
			<classes dir="${classes.dir}"/>
			<fileset dir="${war.dir}" />
		</war>
	</target>

	<target name="rrmwar" description="rm project.war file from remote">
		<ftp action="del" userid="${ftp.username}" password="${ftp.password}" server="${ftp.host}">
			<fileset>
				<include name="${ftp.remotedir}/${ant.project.name}.war"/>
				<include name="${ftp.remotedir}/${ant.project.name}/**"/>
			</fileset>
		</ftp>
	</target>

	<target name="rrm" depends="rrmwar" description="rm project folder from remote">
		<ftp action="rmdir" userid="${ftp.username}" password="${ftp.password}" server="${ftp.host}"
			 remotedir="${ftp.remotedir}">
			<fileset>
				<include name="${ant.project.name}"/>
				<include name="${ant.project.name}/**"/>
			</fileset>
		</ftp>
	</target>
	
	<target name="rupload" depends="war,rrm" description="upload war file to remote ftp" >
		<ftp userid="${ftp.username}" password="${ftp.password}" server="${ftp.host}" remotedir="${ftp.remotedir}">
			<fileset dir="${war.dest}" />
		</ftp>
	</target>

	<target name="stop" description="stop tomcat on Mac OS [lvjian]">
		<exec executable="/Users/lvjian/tomcat6/bin/shutdown.sh" />
	</target>
	<target name="start" description="startup tomcat on Mac OS [lvjian]">
		<exec executable="/Users/lvjian/tomcat6/bin/startup.sh" />
	</target>

	<target name="clean" description="delete classes folder">
		<echo>clean path: ${classes.dir}</echo>
		<delete dir="${classes.dir}"/>
	</target>

	<target name="import">
		<java fork="true" classname="tools.ImportShiro" classpathref="test-classpath">
			<classpath path="${classes.dir}"/>
			<arg value="C:\\export.xml"/>
		</java>
	</target>

	<target name="dbhelp" depends="compile" description="help [hibernate export tools]">
		<java fork="true" classname="dayang.tools.db.HibernateSchemaExport"
				classpathref="test-classpath">
			<classpath path="${classes.dir}"/>
			<arg value="-h" />
		</java>
	</target>

	<target name="dbcreate" depends="compile" 
			description="create database [hibernate export tools]">

		<java fork="true" classname="dayang.tools.db.HibernateSchemaExport"
				classpathref="test-classpath">
			<classpath path="${classes.dir}"/>
			<arg value="-a" />
			<arg value="create" />
			<arg value="-f" />
			<arg value="dayang/tools/db/workflow.cfg.xml" />

		</java>
	</target>

	<target name="dbupdate" depends="compile"
			description="update database [hibernate export tools]">

		<java fork="true" classname="dayang.tools.db.HibernateSchemaExport"
				classpathref="test-classpath">
			<classpath path="${classes.dir}"/>
			<arg value="-a" />
			<arg value="update" />
			<arg value="-f" />
			<arg value="dayang/tools/db/workflow.cfg.xml" />
		</java>
	</target>

</project>