Eclipse的管理的Web项目太多了,以前都是一个Web项目就对应写一个Context.xml文件,然后把它复制到Tomcat下部署,项目一多部署的应用就多了,启动也很费时间。所以写了个Ant Build文件每个项目配置一个启动前运行一下这个Build文件就可以了。
文件里有一些地方是要根据具体情况去修改的。
文件里有一些地方是要根据具体情况去修改的。
<?xml version="1.0" encoding="UTF-8"?>
<project name="mboss" default="deploy" basedir=".">
<!-- TOMCAT目录 -->
<property name="tomcat.home" value="E:/Server/Apache Tomcat 6.0.16" />
<!-- WEB目录 -->
<property name="webdir" value="${basedir}\target\MBossRule-0.0.1-SNAPSHOT" />
<!-- TOMCAT的部署文件名 -->
<property name="deployFileName" value="${ant.project.name}.xml" />
<!-- Servlet的上下文路径 -->
<property name="servletContextName" value="${ant.project.name}" />
<property name="tomcat.home.backup" value="${tomcat.home}/backup" />
<property name="tomcat.home.conf" value="${tomcat.home}/conf/Catalina/localhost" />
<target name="init">
<echo message="Build ${ant.project.name}" />
<mkdir dir="${tomcat.home.backup}" />
</target>
<target name="backup" depends="init">
<echo message="Backup files" />
<copy todir="${tomcat.home.backup}">
<fileset dir="${tomcat.home.conf}" />
</copy>
</target>
<target name="deleteOtherApplicationDeployFiles" depends="backup">
<echo message="Delete Other Application Deploy Files" />
<delete>
<fileset dir="${tomcat.home.conf}">
<exclude name="admin.xml" />
<exclude name="balancer.xml" />
<exclude name="manager.xml" />
</fileset>
</delete>
</target>
<condition property="deployFileExist">
<not>
<available file="${deployFileName}" type="file" />
</not>
</condition>
<target name="createDeployFile">
<echo file="${deployFileName}">
<![CDATA[<Context path="/${servletContextName}" docBase="${webdir}" debug="3"/>]]>
</echo>
<loadfile property="deployFile" srcfile="${deployFileName}" encoding="UTF-8"/>
<echo message="Tomcat Deploy File Content:"/>
<echo message="${deployFile}"/>
<echo message="Access URL: http://localhost:8080/${servletContextName} "/>
</target>
<target name="deployApplication" depends="createDeployFile, deleteOtherApplicationDeployFiles">
<copy todir="${tomcat.home.conf}">
<fileset dir="${basedir}">
<include name="${deployFileName}" />
</fileset>
</copy>
</target>
<target name="deploy" depends="deployApplication">
<echo message="deploy application" />
</target>
</project>