首页 > 代码库 > Ant编译和部署java web项目
Ant编译和部署java web项目
1.在myeclipse中创建javaWeb项目AntDemo
2.将build.xml放到AntDemo根目录下
3.修改build.xml中的Project name,工程目录名,工程名,还有tomcat路径
4.右键->properties->builders->新建一个build,指向你刚刚创建的build.xml
5.选中build.xml->run as Ant Builder就ok了
Ant脚本build.xml
<?xml version="1.0" encoding="gbk"?><project name="AntDemo" default="build" basedir="."> <!-- 工程根目录 --> <property name="AntDemo.home" value="http://www.mamicode.com/."/> <!-- 工程根名 --> <property name="AntDemo.name" value="http://www.mamicode.com/AntDemo"/> <!-- tomcat路径 --> <!-- <property name="tomcat.home" value="D:/Program Files/apache-tomcat-7.0.54/apache-tomcat-7.0.54"/> --> <property name="tomcat.home" value="D:/Program Files/apache-tomcat-7.0.54/apache-tomcat-7.0.54"/> <!-- tomcat部署路径 --> <property name="webapps.home" value="http://www.mamicode.com/${tomcat.home}/webapps"/> <!-- JAVA源文件路径 --> <property name="src.home" value="http://www.mamicode.com/${AntDemo.home}/src"/> <!-- class文件存放位置 --> <property name="classes.home" value="http://www.mamicode.com/${AntDemo.home}/classes"/> <!-- 发布文件夹 --> <property name="deploy.home" value="http://www.mamicode.com/${webapps.home}"/> <!-- <property name="deploy.home" value="http://www.mamicode.com/${webapps.home}/deploy"/> --> <!-- webRoot路径 --> <property name="web.home" value="http://www.mamicode.com/${AntDemo.home}/WebRoot"/> <!-- 创建工程路径 --> <property name="build.home" value="http://www.mamicode.com/${AntDemo.home}/build"/> <!-- /WEB-INF/classes --> <property name="build.classes" value="http://www.mamicode.com/${AntDemo.home}/WEB-INF/classes"/> <!-- /WEB-INF/lib --> <property name="build.lib" value="http://www.mamicode.com/${AntDemo.home}/WEB-INF/lib"/> <!-- 工程引用包 --> <property name="lib.home" value="http://www.mamicode.com/${web.home}/WEB-INF/lib"/> <!-- 编译工程所需的JAR包 --> <path id="compile.classpath"> <pathelement location="${classes.home}"/> <fileset dir="${lib.home}"> <include name="*.jar"/> <include name="*.zip"/> </fileset> <fileset dir="${tomcat.home}/lib"> <include name="*.jar"/> </fileset> <pathelement location="${tomcat.home}/common/classes"/> </path> <!-- 测试ANT --> <target name="help"> <echo message="Please specify a target![usage:ant‘targetname‘]"/> <echo message="Here is a list of possible targets:"/> <echo message=" clean-all....Delete build dir,all .class and war files"/> <echo message=" perpare....Creates directories if requied"/> <echo message=" compile....Compiles source files"/> <echo message=" build......Build war file from.class and other files"/> <echo message=" deploy......Copy war file to the webapps directory"/> </target> <!-- 清除 --> <target name="clean-all"> <delete dir="${build.home}"/> <delete dir="${classes.home}"/> <delete dir="${deploy.home}"/> <delete dir="${webapps.home}/${AntDemo.home}" failonerror="false"/> <delete dir="${webapps.home}/work/" /> <delete dir="${webapps.home}/${AntDemo.name}.war"/> </target> <!-- 准备工作 --> <target name="prepare" depends="clean-all"> <echo message="Tomcat Home=${tomcat.home}"/> <echo message="Webapps Home=${webapps.home}"/> <echo message="classes Home=${classes.home}"/> <echo message="war Home=${deploy.home}"/> <echo message="Java src Home=${src.home}"/> <mkdir dir="${classes.home}"/> <mkdir dir="${deploy.home}"/> <mkdir dir="${build.home}"/> <mkdir dir="${build.home}/WEB-INF"/> <mkdir dir="${build.home}/WEB-INF/classes"/> <mkdir dir="${build.home}/WEB-INF/lib"/> </target> <!-- 编译 --> <target name="compile" depends="prepare"> <javac srcdir="${src.home}" destdir="${classes.home}" includeantruntime="on" debug="true"> <compilerarg line="-encoding UTF-8"/> <classpath refid="compile.classpath"/> </javac> </target> <!-- 构建临时工程 --> <target name="build" depends="compile"> <copy todir="${build.home}"> <fileset dir="${web.home}"/> </copy> <copy todir="${build.home}/WEB-INF/classes"> <fileset dir="${classes.home}"/> </copy> <copy todir="${build.home}/WEB-INF/classes"> <fileset dir="${src.home}"> <include name="**/*.properties"/> <include name="**/*.prop"/> </fileset> </copy> <jar jarfile="${deploy.home}/${AntDemo.name}.war" basedir="${build.home}"/> </target> <!-- 发布 --> <target name="deploy" depends="build"> <copy todir="${webapps.home}" file="${deploy.home}/${AntDemo.name}.war"/> </target></project>
Ant编译和部署java web项目
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。