2013-07-05 35 views
0

我正在使用下面提到的ant build腳本部署我的應用程序。我的應用程序被部署在我的ant腳本中提到的指定服務器上。但是我想在部署新項目之前收回遠程服務器上現有的已部署項目。這是我的螞蟻腳本。如何使用螞蟻備份遠程服務器的現有項目

<?xml version="1.0"?> 
<project name="xyz" basedir="." default="deploy"> 

<!-- Read values from buildscript properties file --> 
<property file="buildscript.properties" /> 

<!-- set global variable for this build --> 
<property name="build" value="${basedir}/build"/> 
<property name="src.dir"  value="src"/> 
<property name="build.dir" value="build"/> 
<property name="classes.dir" value="${build.dir}/classes"/> 
<property name="war.dir"  value="${build.dir}/war"/> 

<!-- Configure the context path for this application --> 
<property name="path"  value="/xyz"/> 

<!-- set class path --> 
<path id="compile.classpath"> 
    <fileset dir="WebContent/WEB-INF/lib"> 
    <include name="*.jar"/> 
    </fileset> 
    <fileset dir="${tomcatDir}"> 
    <include name="*.jar"/> 
    </fileset> 
</path> 

<!-- Configure the custom Ant tasks for the Tomcat Server Manager --> 
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"> 
    <classpath refid="compile.classpath" /> 
</taskdef> 
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"> 
     <classpath refid="compile.classpath" /> 
</taskdef> 
<taskdef name="start" classname="org.apache.catalina.ant.StartTask"> 
    <classpath refid="compile.classpath" /> 
</taskdef> 
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask"> 
    <classpath refid="compile.classpath" /> 
</taskdef> 

<!-- delete build directory --> 
<target name="clean"> 
     <delete dir="${build.dir}"/> 
    </target> 

<!-- create classes, war directory in build --> 
<target name="create" depends="clean"> 
    <mkdir dir="${classes.dir}"/> 
    <mkdir dir="${war.dir}"/> 
</target> 

<!-- compile source code and put classes in classes dir --> 
<target name="compile" depends="create"> 
    <copy todir="${classes.dir}" overwrite="true"> 
     <fileset dir="src" excludes="*.java"/> 
    </copy> 
    <!-- for replacing cfg file to deploy on stagging--> 
    <copy todir="${classes.dir}" overwrite="true"> 
     <fileset dir="${configurationFileDir}"> 
      <include name="*.xml"/>  
     </fileset> 
    </copy> 
    <javac destdir="${classes.dir}" srcdir="${src.dir}" debug="true"> 
    <classpath refid="compile.classpath"/> 
    </javac> 
</target> 

<!-- create war file --> 
<target name="war" depends="compile"> 
    <war destfile="${war.dir}/xyz.war" webxml="WebContent/WEB-INF/web.xml"> 
    <fileset dir="WebContent"/>  
    <classes dir="build/classes"/> 
    </war> 
</target> 

<!-- Deploy war file --> 
<target name="deploy" description="Install web application" 
    depends="war"> 
    <deploy url="${url}" username="${username}" password="${password}" 
      path="${path}" war="file:${war.dir}/xyz.war"/> 
</target> 

<!-- Start apllication --> 
<target name="start" description="start application in tomcat"> 
<start url="${url}" username="${username}" password="${password}" path="${path}"/> 
</target> 

<!-- Undeploy war file --> 
<target name="undeploy" description="Remove web application" > 
     <undeploy url="${url}" username="${username}" password="${password}" 
       path="${path}"/> 
</target> 
<!-- Stop apllication --> 
<target name="stop" description="stop application in tomcat"> 
    <stop url="${url}" username="${username}" password="${password}" path="${path}"/> 
</target> 

</project> 

回答

0

經理文檔描述了special tag attribute可以用來重新部署應用程序:

URL參數包括:

update: When set to true, any existing update will be undeployed first.... 
tag: Specifying a tag name, this allows associating the deployed webapp 
     with a tag or label. If the web application is undeployed, it can be 
     later redeployed when needed using only the tag. 

不幸的是,ANT任務文檔不介紹對此屬性的任何支持...

有趣的是,Maven plugin確實支持這一點,但切換構建工具將是這個問題的一個相當極端的解決方案:-)