0

我正在使用下面提到的 ant 构建脚本部署我的应用程序。我的应用程序部署在我的 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>
4

1 回答 1

0

管理器文档描述了一个特殊的标签属性,可用于重新部署您的应用程序:

网址参数包括:

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 插件确实支持这一点,但是切换构建工具将是解决这个问题的一个相当极端的解决方案 :-)

于 2013-07-05T09:25:28.987 回答