Typically, when Web applications need to be online or tested, they typically need to be deployed to Web servers like Tomcat, JBoss, WebLogic, or webspare, to avoid the tedious and error-prone aspects of manual deployment, where ant is used for standardized deployment. Here my Web server uses the Nginx+tomcat cluster, so the ant script that needs to be written is as follows:
<?xml version= "1.0" encoding= "UTF-8"? ><project name= "Oprmonitor-user" basedir= "."default= "Redeploy" > <!--System Environment configuration--<property environment= "env"/> <!--source path--<property NA Me= "Src.dir" value= "${basedir}/src"/> <!--compilation path--<property name= "Dist.dir" value= "${basedir}/dist"/ > <!--static resource path--<property name= "Web.root.dir" value= "${basedir}/webroot"/> <!--current project Classpath--&G T <property name= "Lib.dir" value= "${basedir}/webroot/web-inf/lib"/> <!--Deployment Descriptor path--<property name= "W Eb.xml.dir "value=" ${basedir}/webroot/web-inf/web.xml "/> <!--War Package name--<property name=" War.name "Valu E= "Oprmonitor-user"/> <!--Tomcat path--<property name= "Tomcat.dir" value= "D:/soft/apache/apache-tomcat -7.0.67 "/> <!--Tomcat executable script path--<property name=" Tomcat.bin.dir "value=" ${tomcat.dir}/bin "/> &L t;! --Tomcat Publish app path--<property name= "Tomcat.webapps.dir" value= "${tomcat.dir}/webapps"/> <!--Tomcat Publishing log Path--<property name= "Tomcat.logs.dir" value= "${tomcat.dir}/logs"/> <!--current time--<tstamp> <for Mat property= "Current.time" pattern= "Yyyymmddhhmmss" locale= "zh"/> </tstamp> <path id= "Build-classpath" > <fileset dir= "${lib.dir}" > <include name= "**/*.jar"/> </fileset> </ path> <target name= "init" description= "Verify operating System" > <echo> Verify operating system ...</echo> <echo>$ {os.name}</echo> <echo> Verify operating system completion </echo> </target> <target name= "clean" depends= "ini T "description=" clears the old compiled file "> <echo> is clearing the old compiled file ...</echo> <delete dir=" ${dist.dir} "/> <mkdir dir= "${dist.dir}"/> <echo> clear Old compilation file complete </echo> </target> <target name= "com Pile "depends=" clean "description=" compiled source > <echo> compiling source ...</echo> <javac srcdir= "${src.dir} "Destdir=" ${dist.dir} "Includeantruntime= "false" > <compilerarg line= "-encoding UTF-8"/> <classpath refid= "Build-classpath"/> ; </javac> <echo> Compile source completion </echo> </target> <target name= "Generate-war" depends= "Compil E "description=" Build War Package "> <echo> is generating War package ...</echo> <delete dir=" ${basedir}/${war.name}.war " /> <war destfile= "${basedir}/${war.name}.war" webxml= "${web.xml.dir}"excludes= "*.SVN" > <fileset dir= "${web.root.dir}" > <include name= "**/**.*"/> <exclude name= "**/*.jar"/> <exclude name= "**/*.class"/> </fileset> <lib dir= "${lib.dir}"/> <classes dir= "${dist.dir}"/> </war> <echo> Generate War Package completion </echo> </target> <target name= "Stop-tomcat" depends= "Generate-war" description= "Stop Tomcat" &G T <echo> closing tomcat...</echo> <exec executable= "${tomcat.bin.dir}/shutdown.bat" failonerror= "false"Output= "${tomcat.logs.dir}/log.txt" append= "true" > <env key= "catalina_home" path= "${tomcat.dir}"/> <arg value= "/C Shutdown.bat"/> </exec> <!--detect if the URL for Tomcat fails (with not tag), access failure is that Tomcat is closed --<waitfor maxwait= "5" maxwaitunit= "Minute" checkevery= "5" > <not> Description= "Check for the existence of the old war package with the same name" > <echo> Check if the old war package with the same name exists ...</echo> <available file= "${tomcat.dir}/webapps/$ {War.name}.war " Property= "Old-war-isexist"/> </target> <target name= "Backup-old-war" depends= "Old-war-exist-check"if= "Old-war-isexist"Description= "Backup if old war package exists with the same name" > <echo> Old War package with the same name [present], start backup ...</echo> <copy tofile= "${tomcat.dir}/webapps/ ${war.name}.war.bak.${current.time} "> <fileset file=" ${tomcat.dir}/webapps/${war.name}.war "/> </copy> <echo> Legacy War Package [presence], Backup complete </echo> </target> <target name= "Delete-old-war" dep Ends= "Backup-old-war"if= "Old-war-isexist"Description= "Delete if the old war package with the same name is complete" > <echo> delete the Old war package with the same name ...</echo> <delete file= "${tomcat.dir}/webapps/${wa R.name}.war "/> <echo> Delete old same name war package complete </echo> <echo> Delete old war with the same name unzipped project ...</echo> & Lt;delete dir= "${tomcat.dir}/webapps/${war.name}"/> <echo> delete old war with the same name unzipped project complete </echo> </target> ; <target name= "Copy-new-war-into-webapps" depends= "Delete-old-war"Description= "Copy the new war package into Tomcat's WebApps" > <echo> Copy the new war package into Tomcat's WebApps directory ...</echo> <copy tofile= "${t Omcat.webapps.dir}/${war.name}.war "> <fileset file=" ${basedir}/${war.name}.war "/> </copy> ; <echo> Copy the new war package into Tomcat's WebApps directory complete </echo> </target> <target name= "Start-tomcat" depends= " Copy-new-war-into-webapps "Description= "Boot Tomcat" > <echo> starting tomcat...</echo> <exec executable= "${tomcat.bin.dir}/startup.bat" f Ailonerror= "false"Vmlauncher= "false" output= "${tomcat.logs.dir}/log.txt" append= "true" > <env key= "catalina_home" path= "${tomcat.dir}" /> <arg value= "/C Startup.bat"/> </exec> <!--detect if a tomcat URL can be accessed successfully, the successful access is that Tom Cat boot Complete-<waitfor maxwait= "5" maxwaitunit= "Minute" checkevery= "5" > Publishing Web projects with Ant automation