今天研究对象是Ant,用于对msms系统进行Tomcat的自动部署。
遇到一个怪问题,百思不得其解:
通过ant depoly可以把msms.war部署到tomcat上。当然,要求这时候webapps下面没有msms目录。
看tomcat的纪录,加载msms.war正常,网页也可以打开。
通过ant undeploy,可以把msms卸载。Tomcat显示:
Undeploying context [/msms]
正常卸载了。问题是,去看webapps目录下面,居然有一个msms目录的残骸,里面保留的目录是
WEB-INF\lib
有以下几个文件残留着:
commons-digester.jar
commons-validator.jar
struts.jar
这时候msms目录也无法手工删除,必须停掉tomcat后才能删除。
我装的tomcat是5.5。不知道是否还有人遇到过这种情况,我反正是晕了。
build.properties文件如下:
tomcat.dir=C:/ApacheGroup/Tomcat5.5
tomcat.webapps=C:/ApacheGroup/Tomcat5.5/webapps
tomcat.manager.url=http://localhost:8080/manager
tomcat.manager.username=admin
tomcat.manager.password=xxxxxxxx
build.xml文件如下:
<?xml version="1.0"?>
<project name="msms" default="compile" basedir=".">
<!-- Ant Tomcat Task Definition -->
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask">
<classpath>
<path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask">
<classpath>
<path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
<classpath>
<path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath>
<path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath>
<path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath>
<path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath>
<path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<property name="build" value="build" />
<property name="dist" value="dist" />
<property name="src" value="src/java" />
<property name="test" value="src/test" />
<property name="war-config" value="src/config" />
<property name="report" value="report" />
<property name="lib" value="lib" />
<property name="web" value="web" />
<property name="meta" value="meta" />
<property name="context-path" value="${ant.project.name}" />
<property file="build.properties" />
<path id="build.classpath">
<fileset file="${lib}/*.jar" />
<fileset dir="${tomcat.dir}/common/lib">
<include name="*.jar" />
</fileset>
<fileset dir="${tomcat.dir}/common/endorsed">
<include name="*.jar" />
</fileset>
<pathelement path="${build}" />
</path>
<!-- Hibernate Tool Task Definition -->
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="build.classpath" />
<target name="clean">
<echo message="Cleaning up the build and dist directories" />
<delete dir="${build}" />
<mkdir dir="${build}" />
<delete dir="${dist}" />
<mkdir dir="${dist}" />
</target>
<target name="copy-resources">
<copy todir="${build}">
<fileset dir="${src}">
<exclude name="**/*.java" />
<exclude name="**/*.hbm.xml" />
</fileset>
</copy>
</target>
<target name="compile" depends="copy-resources">
<javac destdir="${build}" srcdir="${src}:${test}">
<classpath refid="build.classpath" />
</javac>
</target>
<target name="initdb" depends="compile">
<hibernatetool destdir="${build}">
<classpath>
<path location="${build}" />
</classpath>
<annotationconfiguration
configurationfile="src/java/hibernate.cfg.xml" />
<hbm2ddl create="true" />
</hibernatetool>
</target>
<target name="run" depends="compile">
<java fork="true"
classname="cn.ac.rcpa.msms.tools.ProjectManager"
classpathref="build.classpath">
<classpath path="${build}" />
<arg value="${action}" />
<arg value="${project}" />
<arg value="${description}" />
</java>
</target>
<target name="test" depends="compile" description="run junit test">
<delete dir="${report}" />
<mkdir dir="${report}" />
<junit dir="." fork="true"
printsummary="on" haltonfailure="false" failureproperty="tests.failed"
showoutput="true">
<classpath refid="build.classpath" />
<formatter type="brief" />
<batchtest todir="${report}">
<fileset dir="${build}">
<include name="**/*Test.*"
/>
<include name="**/Test*.*"
/>
</fileset>
</batchtest>
</junit>
<fail if="tests.failed">
***********************************************************
**** One or more tests failed! Check the output ... ****
***********************************************************
</fail>
</target>
<target name="create-war" depends="clean, compile" description="build release war">
<echo message="creation the WAR file...${context-path}.war" />
<war destfile="${dist}/${context-path}.war" webxml="${meta}/web.xml">
<classes dir="${build}">
<exclude name="**/*Test.*" />
<exclude name="**/Test*.*" />
<exclude name="hibernate.cfg.xml" />
</classes>
<lib dir="${lib}" />
<fileset dir="${web}" />
<zipfileset dir="${war-config}" prefix="WEB-INF/classes" />
</war>
<!--
<scp file="${dist}/${context-path}.war"
todir="root:${password}@172.16.1.20:/usr/local/tomcat/webapps"
trust="true" /> -->
</target>
<target name="deploy" description="Install application in Tomcat">
<deploy
url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}" path="/${context-path}"
localWar="file:${dist}/${context-path}.war" />
</target>
<target name="undeploy" description="Remove application in Tomcat" if="already.deployed">
<undeploy
url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}" path="/${context-path}" />
</target>
<target name="reload" description="Reload application in Tomcat">
<reload
url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}" path="/${context-path}" />
</target>
<target name="start" description="Start Tomcat application">
<start
url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}" path="/${context-path}" />
</target>
<target name="stop" description="Stop Tomcat application">
<stop
url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}" path="/${context-path}" />
</target>
<target name="list" description="List Tomcat applications">
<list
url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}" />
</target>
<target name="deploy-application" description="Compile the web application...">
<echo message="Undeploying the application only if it's deployed..." />
<available
file="${tomcat.webapps}/${context-path}.war"
property="already.deployed" />
<antcall target="undeploy" />
<antcall target="create-war" />
<antcall target="deploy" />
</target>
</project>