晚上eclipse不知道怎么的,總是不停的編譯,一打開tomcat就死掉。郁悶的很,自己寫了一個ant命令來編譯和部署web了。代碼如下:
配置信息build.properties
# Source Directory
src.dir=${basedir}/src
# Resource Directory
resources.dir=${basedir}/resources
# War name
war.name=${ant.project.name}
# web context directory
war.dir=${basedir}/WebContent
# Library directory within project. Where third party jars reside.
lib.dir = ${war.dir}/WEB-INF/lib
# All artifacts produced by the build go somewhere underneath the target dir
build.dir=${war.dir}/WEB-INF/classes
# Directory we generate distribution units such as jars and zips to
target.dir = ${basedir}/target
# Test Directory
test.dir=${basedir}/test
test.target.dir=${basedir}/target/test/classes
test.report.dir=${basedir}/target/test/report
test.data=${basedir}/target/test/data
funtest.dir=${basedir}/funtest
funtest.target.dir=${basedir}/target/funtest/classes
funtest.report.dir=${basedir}/target/funtest/report
funtest.data=${basedir}/target/funtest/data
# Tomcat Home Directory
tomcat.home=C:\\Program Files\\apache-tomcat-
tomcat.port=8080
# Release name and version
project.version=0.1
project.name=${ant.project.name}
ant運行的主要文件build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="greatwall" basedir="." default="deploy">
<property file="build.properties" />
<property
name="web.home" value="/C:/Program Files/apache-tomcat-
<path id="all-libs">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${tomcat.home}/lib">
<include name="**/*.jar" />
</fileset>
</path>
<!-- ===================================
編譯Java文件并復(fù)制資源文件
==================================== -->
<target name="build" description="Compile main Java sources">
<mkdir dir="${build.dir}" />
<echo>Compile main Java sources...</echo>
<javac destdir="${build.dir}" target="1.5" debug="true" deprecation="true" optimize="false" failonerror="true">
<src path="${src.dir}" />
<!-- <compilerarg line="-encoding UTF-8" /> -->
<classpath refid="all-libs" />
</javac>
<!-- copy other none java files such as hibernate hbm.xml files, workflow files files -->
<echo>Copy other none java files...</echo>
<copy todir="${build.dir}" preservelastmodified="true">
<fileset dir="${src.dir}">
<exclude name="**/*.java" />
<exclude name="**/*.bak" />
</fileset>
</copy>
</target>
<target name="war" depends="build" description="Create WAR deployment unit">
<mkdir dir="${target.dir}" />
<echo>Create WAR deployment unit...</echo>
<war warfile="${target.dir}/${war.name}.war" webxml="${war.dir}/WEB-INF/web.xml">
<!-- Include the css, images and other documents -->
<fileset dir="${war.dir}" excludes="WEB-INF/**" />
<webinf dir="${war.dir}/WEB-INF">
<exclude name="classes/**" />
<exclude name="web.xml" />
</webinf>
<!-- Include the compiled classes -->
<classes dir="${build.dir}" />
<lib dir="${lib.dir}" includes="*.jar" />
<exclude name="${war.dir}/WEB-INF/lib/servlet.jar" />
</war>
</target>
<target name="deploy" depends="build" description="Deploy the applycation to Tomcat">
<echo>Deploy the applycation to Tomcat...</echo>
<copy todir="${web.home}">
<fileset dir="${war.dir}">
<exclude name="**/*.bak" />
<exclude name="CVS" />
</fileset>
</copy>
</target>
</project>