沉睡森林@漂在北京

本处文章除注明“转载”外均为原创,转载请注明出处。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  152 随笔 :: 4 文章 :: 114 评论 :: 0 Trackbacks

晚上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-6.0.18

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-6.0.18/webapps/greatwall" />

      

       <path id="all-libs">

              <fileset dir="${lib.dir}">

                     <include name="**/*.jar" />

              </fileset>

              <fileset dir="${tomcat.home}/lib">

                     <include name="**/*.jar" />

              </fileset>

       </path>

      

       <!-- ===================================

       编译Java文件并复制资源文件

       ==================================== -->

       <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>

 

posted on 2008-11-09 23:14 王总兵 阅读(286) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: