使用Ant部署应用程序系统
1. 首先下载Ant http://ant.apache.org/ 配置环境变量
2. 编写build.xml部署文件如下:
<?xml version="1.0" encoding="UTF-8"?> <project name="fspdrs" default="deploy" basedir="."> <description>使用【Apache Ant】部署主评审系统</description> <target name="about" description="关于"> <echo>#####################</echo> <echo>【部署FSPDRS主评审系统】</echo> <echo>#####################</echo> <echo>只需修改【Tomcat根路径】为您要部署的服务器路径即可</echo> </target> <target name="init" depends="about" description="创建目录结构"> <echo message="###########初始化开始...###########"/> <property environment="myenv"/> <!--项目名称--> <property name="webapp.name" value="fspdrs" /> <!--项目的WebRoot路径--> <property name="webRoot.dir" value="${basedir}/WebRoot" /> <!--项目的lib包路径--> <property name="lib.dir" value="${webRoot.dir}/WEB-INF/lib" /> <!--Tomcat根路径--> <property name="tomcatRoot.dir" value="D:/Server/apache-tomcat-7.0.33" /> <!--项目srcPath类路径--> <property name="srcPath" value="src/main/java"/> <!--项目ClassPath类路径--> <property name="classesPath" value="${webRoot.dir}/WEB-INF/classes"/> <!--使用eclipse jdt进行编译,而不使用JDK编译--> <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" /> <!--JavaDoc配置--> <property name="packages" value="com.*.*.*" /> <property name="locale" value="en_US" /> <property name="encoding" value="utf-8" /> <property name="docencoding" value="utf-8" /> <property name="charset" value="utf-8" /> <property name="javaDocPath" value="${basedir}\javadoc"/> <property name="additionalParam" value="-encoding UTF-8 -charset UTF-8" /> <!-- 自动部署配置 --> <property name="url" value="http://localhost:8001/manager" /> <property name="username" value="tomcat" /> <property name="password" value="tomcat" /> <!--初始化环境变量--> <path id="compile.classpath" description="编译需要的JAR包"> <fileset dir="${lib.dir}"> <include name="*.jar"/> </fileset> <fileset dir="${tomcatRoot.dir}/lib"> <include name="*.jar"/> </fileset> </path> <echo message="###########初始化结束!###########"/> </target> <target name="compile" depends="init" description="编译java文件"> <echo message="###########开始编译...###########" /> <javac srcdir="${srcPath}" destdir="${classesPath}" includeantruntime="false" nowarn="on" source="1.6" target="1.6" deprecation="true" debug="true" encoding="UTF-8" classpathref="compile.classpath"> </javac> <copy todir="${classesPath}"> <fileset dir="${srcPath}"> <include name="**/*.xml" /> <include name="**/*.properties" /> </fileset> </copy> <echo message="###########编译结束!###########" /> </target> <target name="javadoc" depends="compile"> <mkdir dir="${javaDocPath}"/> <javadoc packagenames="${packages}" sourcepath="${srcPath}" destdir="${javaDocPath}" encoding="${encoding}" docencoding="${docencoding}" locale="${locale}" additionalparam="${additionalParam}" author="true" version="true" use="true" splitindex="true" windowtitle="${webapp.name} API" doctitle="${webapp.name}"> <classpath refid="compile.classpath" /> </javadoc> </target> <target name="deploy" depends="compile" description="拷贝部署文件"> <echo message="###########拷贝文件开始,请稍后...###########"/> <!--创建部署的项目名称fspdrs路径--> <mkdir dir="${tomcatRoot.dir}\webapps\${webapp.name}"/> <!--创建部署的项目WEB-INF路径--> <mkdir dir="${tomcatRoot.dir}\webapps\${webapp.name}\WEB-INF"/> <!--创建部署的项目的类classes路径--> <mkdir dir="${tomcatRoot.dir}\webapps\${webapp.name}\WEB-INF\classes"/> <copy todir="${tomcatRoot.dir}/webapps/${webapp.name}"> <fileset dir="${webRoot.dir}"> <include name="generalsearch_template/**"/> <include name="help/**"/> <include name="images/**"/> <include name="installerSoft/**"/> <include name="rpt_template/**"/> <include name="script/**"/> <include name="style/**"/> <include name="taglibs/**"/> <include name="weboffice/**"/> <include name="temp/**"/> <include name="WEB-INF/**"/> <include name="403.jsp"/> <include name="404.jsp"/> <include name="500.jsp"/> <include name="code.jsp"/> <include name="error.jsp"/> <include name="login.jsp"/> <include name="timeout.jsp"/> </fileset> </copy> <echo message="###########拷贝文件结束!###########" /> </target> <target name="war" depends="compile" description="将工程打成war包"> <echo message="###########创建 war开始...###########" /> <war destfile="${tomcatRoot.dir}/webapps/${webapp.name}.war" webxml="${webRoot.dir}/WEB-INF/web.xml"> <lib dir="${lib.dir}" /> <classes dir="${classesPath}" /> <fileset dir="${webRoot.dir}"> <include name="generalsearch_template/**"/> <include name="help/**"/> <include name="images/**"/> <include name="installerSoft/**"/> <include name="rpt_template/**"/> <include name="script/**"/> <include name="style/**"/> <include name="taglibs/**"/> <include name="weboffice/**"/> <include name="temp/**"/> <include name="WEB-INF/**"/> <exclude name="WEB-INF/classes/**"/> <include name="403.jsp"/> <include name="404.jsp"/> <include name="500.jsp"/> <include name="code.jsp"/> <include name="error.jsp"/> <include name="login.jsp"/> <include name="timeout.jsp"/> </fileset> </war> <echo message="###########创建 war结束!###########" /> </target> </project>