ant 自动编译 build.xml 配置
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project name="wanshun" default="deploy" basedir="."> 3 <property environment="env" /> 4 <property name="webapp.name" value="wanshun" /> 5 <!--tomcat路径修改此处即可--> 6 <property name="catalina.home" value="/var/tomcats/tomcat9080" /> 7 <property name="dist.dir" value="${basedir}/dist" /> 8 <property name="ant.dir" value="/data/word_app" /> 9 <property name="webRoot.dir" value="${basedir}/WebRoot" /> 10 <property name="src.dir" value="${basedir}/src" /> 11 <property name="config.dir" value="${basedir}/etc" /> 12 <property name="lib.dir" value="${webRoot.dir}/WEB-INF/lib" /> 13 <property name="build.dir" value="${basedir}/build" /> 14 <!-- 使用eclipse jdt进行编译,而不使用JDK编译 --> 15 <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" /> 16 17 <!-- 初始化classpath --> 18 <path id="project.classpath"> 19 <fileset dir="${lib.dir}"> 20 <include name="**/*.jar" /> 21 </fileset> 22 <!-- 添加tomcat类路径 --> 23 <fileset dir="${catalina.home}/lib"> 24 <include name="*.jar" /> 25 </fileset> 26 <!-- ant lib包 --> 27 <fileset dir="${ant.dir}"> 28 <include name="**/*.jar" /> 29 </fileset> 30 </path> 31 32 <!-- get the source compile classpath in a printable form --> 33 <pathconvert pathsep="${line.separator}| |-- " 34 property="echo.path.compile" 35 refid="project.classpath"> 36 </pathconvert> 37 38 <!-- show classpath jars --> 39 <target name="print_classpath"> 40 <echo message="|-- compile classpath"/> 41 <echo message="| |"/> 42 <echo message="| |-- ${echo.path.compile}"/> 43 </target> 44 45 46 <!-- 删除之前的目录结构 --> 47 <target name="clear" description="清理旧文件"> 48 <delete dir="${build.dir}" /> 49 <delete dir="${dist.dir}" /> 50 <delete file="${catalina.home}/webapps/${webapp.name}.war" /> 51 <delete dir="${catalina.home}/webapps/${webapp.name}" /> 52 </target> 53 54 <!-- 创建目录结构 --> 55 <target name="init" depends="clear" description="创建初始化目录结构"> 56 <mkdir dir="${build.dir}/classes" /> 57 <mkdir dir="${dist.dir}" /> 58 </target> 59 60 <!-- 编译java --> 61 <target name="compile" depends="init" description="编译java文件"> 62 <echo message="begin compile..." /> 63 <javac srcdir="${src.dir}" destdir="${build.dir}/classes" 64 includeantruntime="false" nowarn="on" 65 source="1.8" target="1.8" deprecation="true" debug="true" 66 encoding="UTF-8" classpathref="project.classpath" 67 > 68 <compilerarg line="-Xlint:unchecked" /> 69 <!-- <classpath refid="project.classpath" /> --> 70 </javac> 71 <copy todir="${build.dir}/classes"> 72 <fileset dir="${src.dir}"> 73 <include name="**/*.xml" /> 74 <include name="**/*.properties" /> 75 <include name="**/*.sql" /> 76 </fileset> 77 <fileset dir="${config.dir}"> 78 <include name="**/*.xml" /> 79 <include name="**/*.properties" /> 80 <include name="**/*.sql" /> 81 </fileset> 82 </copy> 83 <echo message="end compile..." /> 84 </target> 85 86 <!-- 将class文件打成 jar包 --> 87 <!-- 88 <target name="pack" depends="compile"> 89 <jar jarfile="${build.dir}/${webapp.name}.jar"> 90 <fileset dir="${build.dir}/classes"> 91 <include name="**/*.class"/> 92 </fileset> 93 </jar> 94 </target> 95 --> 96 97 <!-- 打成war包, 名称默认为 项目名 --> 98 <target name="war" depends="compile" description="将工程打成war包"> 99 <echo message="begin war..." /> 100 <war destfile="${dist.dir}/${webapp.name}.war" basedir="${webRoot.dir}" webxml="${webRoot.dir}/WEB-INF/web.xml"> 101 <lib dir="${lib.dir}" /> 102 <classes dir="${build.dir}/classes" /> 103 <fileset dir="${webRoot.dir}"> 104 <include name="***.*" /> 105 </fileset> 106 </war> 107 <echo message="end war..." /> 108 </target> 109 110 <!-- copy war包 tomcat的deploy目录 --> 111 <target name="deploy" depends="war" description="部署项目"> 112 <echo message="begin deploy..." /> 113 <copy file="${dist.dir}/${webapp.name}.war" todir="${basedir}" /> 114 <echo message="end deploy..." /> 115 </target> 116 117 </project>
备注:JDTCompilerAdapter到eclipse\plugins中检索‘org.eclipse.jdt*’文件;
‘org.eclipse.jdt.core_XXX’取出‘jdtCompilerAdapter.jar’放入ant安装目录/lib中
itjiandan