1.环境变量设置
首先,确定自己的/etc/profile或者/${HOME}/.bashrc下有如下的环境设置:
------
#set java env
export JAVA_HOME=xxx
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASSPATH
#set tomcat env
export TOMCAT_HOME=xxx
#set ant env
export ANT_HOME=xxx
export PATH=$PATH:$ANT_HOME/bin
------
有了以上的设置,就可以使用<property environment="env"/>来找到相关的环境变量。
在shell下可以
[root@localhost ~]# env
查看环境变量。
2.ant脚本位置
根据MyEclipse下Web工程的文件位置放置build.xml(与WebRoot同层):
------
|-src
|-WebRoot
|-WEB-INF
|-META-INF
|-build.xml
------
3.build.xml
该脚本可以将当前的Web工程编译并部署到你的Tomcat的webapps目录下,为避免在webapps下出现工程名相同而覆盖的情况,将使用当前部署时间作为工程名。注意,这里假定使用Tomcat6,它的/lib目录有别于Tomcat5。
首先,确定自己的/etc/profile或者/${HOME}/.bashrc下有如下的环境设置:
------
#set java env
export JAVA_HOME=xxx
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASSPATH
#set tomcat env
export TOMCAT_HOME=xxx
#set ant env
export ANT_HOME=xxx
export PATH=$PATH:$ANT_HOME/bin
------
有了以上的设置,就可以使用<property environment="env"/>来找到相关的环境变量。
在shell下可以
[root@localhost ~]# env
查看环境变量。
2.ant脚本位置
根据MyEclipse下Web工程的文件位置放置build.xml(与WebRoot同层):
------
|-src
|-WebRoot
|-WEB-INF
|-META-INF
|-build.xml
------
3.build.xml
该脚本可以将当前的Web工程编译并部署到你的Tomcat的webapps目录下,为避免在webapps下出现工程名相同而覆盖的情况,将使用当前部署时间作为工程名。注意,这里假定使用Tomcat6,它的/lib目录有别于Tomcat5。
<?
xml
version
="1.0"
encoding
="utf-8"
?>
< project name ="myDeploy" default ="all" basedir ="." >
< property name ="build.dir" value ="${basedir}/build" />
< property name ="src" value ="${basedir}/src" />
< property name ="build.webinf" value ="${basedir}/build/WEB-INF" />
< property name ="build.weblib" value ="${basedir}/build/WEB-INF/lib" />
< property name ="build.metainf" value ="${basedir}/build/META-INF" />
< property name ="build.dest" value ="${basedir}/build/WEB-INF/classes" />
< property environment ="env" />
< target name ="init" >
< tstamp />
< mkdir dir ="${build.dir}" />
< mkdir dir ="${build.webinf}" />
< mkdir dir ="${build.weblib}" />
< mkdir dir ="${build.metainf}" />
< mkdir dir ="${build.dest}" />
< copy todir ="${build.dir}" >
< fileset dir ="${basedir}/WebRoot" >
< include name ="**" />
</ fileset >
</ copy >
</ target >
< target name ="compile" depends ="init" >
< property name ="servletapi"
value ="${env.TOMCAT_HOME}/lib/ * .jar" />
< property name ="locallib"
value ="${build.weblib}/*.jar" />
< javac srcdir ="${src}" destdir ="${build.dest}" classpath ="${servletapi};${locallib}" />
</ target >
< target name ="deploy" depends ="compile" >
< property name ="deploy.dir" value ="${env.TOMCAT_HOME}/webapps/${DSTAMP}${TSTAMP}" />
< mkdir dir ="${deploy.dir}" />
< copy todir ="${deploy.dir}" >
< fileset dir ="${build.dir}" >
< include name ="**" />
</ fileset >
</ copy >
</ target >
< target name ="clean" depends ="init" >
< delete dir ="${build.dir}" />
</ target >
< target name ="all" depends ="deploy,clean"
description ="deploys the project to tomcat and cleans the build files." />
</ project >
< project name ="myDeploy" default ="all" basedir ="." >
< property name ="build.dir" value ="${basedir}/build" />
< property name ="src" value ="${basedir}/src" />
< property name ="build.webinf" value ="${basedir}/build/WEB-INF" />
< property name ="build.weblib" value ="${basedir}/build/WEB-INF/lib" />
< property name ="build.metainf" value ="${basedir}/build/META-INF" />
< property name ="build.dest" value ="${basedir}/build/WEB-INF/classes" />
< property environment ="env" />
< target name ="init" >
< tstamp />
< mkdir dir ="${build.dir}" />
< mkdir dir ="${build.webinf}" />
< mkdir dir ="${build.weblib}" />
< mkdir dir ="${build.metainf}" />
< mkdir dir ="${build.dest}" />
< copy todir ="${build.dir}" >
< fileset dir ="${basedir}/WebRoot" >
< include name ="**" />
</ fileset >
</ copy >
</ target >
< target name ="compile" depends ="init" >
< property name ="servletapi"
value ="${env.TOMCAT_HOME}/lib/ * .jar" />
< property name ="locallib"
value ="${build.weblib}/*.jar" />
< javac srcdir ="${src}" destdir ="${build.dest}" classpath ="${servletapi};${locallib}" />
</ target >
< target name ="deploy" depends ="compile" >
< property name ="deploy.dir" value ="${env.TOMCAT_HOME}/webapps/${DSTAMP}${TSTAMP}" />
< mkdir dir ="${deploy.dir}" />
< copy todir ="${deploy.dir}" >
< fileset dir ="${build.dir}" >
< include name ="**" />
</ fileset >
</ copy >
</ target >
< target name ="clean" depends ="init" >
< delete dir ="${build.dir}" />
</ target >
< target name ="all" depends ="deploy,clean"
description ="deploys the project to tomcat and cleans the build files." />
</ project >