Ant 打包war 生成文件内容build.xml
1. 打包文件内容
?
<?xml version="1.0" encoding="UTF-8"?><project name="newbssqyl" basedir="." default="makewar"> <property name="classpath_lib" value="WebContent/WEB-INF/lib" /> <property name="sources" value="${basedir}/src"/> <path id="classpath"> <fileset dir="${classpath_lib}"> <include name="*.jar"/> </fileset> </path> <property name="debuglevel" value="source,lines,vars"/> <property name="target" value="1.6"/> <property name="source" value="1.6"/> <target name="init"> <property name="build" value="build/destination/webapp"></property> <property name="src" value="src"></property> <mkdir dir="${build}"/> <mkdir dir="${build}\WEB-INF"/> <mkdir dir="${build}\WEB-INF\classes"/> <mkdir dir="${build}\WEB-INF\lib"/> <copy todir="${build}"> <fileset dir="${basedir}\WebContent"> <include name="WEB-INF/**" /> <include name="**" /> </fileset> </copy> </target> <target name="complie" depends="init"> <javac srcdir="${src}" destdir="${build}/WEB-INF/classes" classpathref="classpath"> </javac> </target> <target name="makewar" depends="complie"> <war warfile="${build}/newbssqyl.war" webxml="${build}/WEB-INF/web.xml"> <lib dir="${build}/WEB-INF/lib"> <include name="**" /> </lib> <classes dir="${build}/WEB-INF/classes"/> <fileset dir="${build}"/> </war> </target> </project>
?
2. 将文件放到项目根目录中
\newbssqyl
?
3.运行命令
E:\刘庆\AntProjectTest\test\newbssqyl>ant makewarBuildfile: E:\刘庆\AntProjectTest\test\newbssqyl\build.xmlinit:complie: [javac] E:\刘庆\AntProjectTest\test\newbssqyl\build.xml:34: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable buildsmakewar: [war] Building war: E:\刘庆\AntProjectTest\test\newbssqyl\build\destination\webapp\newbssqyl.warBUILD SUCCESSFULTotal time: 1 minute 59 secondsE:\刘庆\AntProjectTest\test\newbssqyl>
?
?OK 生成成功
?
修正文件
?
<?xml version="1.0" encoding="UTF-8"?> <project name="newbssqyl" basedir="." default="makewar"> <property name="classpath_lib" value="WebContent/WEB-INF/lib" /> <property name="sources" value="${basedir}/src"/> <path id="classpath"><!--添加lib 中的jar 包到软件中--> <fileset dir="${classpath_lib}"> <include name="*.jar"/> </fileset><!--添加lib 之外的包--><fileset dir="D:\Tomcat 6.0\lib"> <include name="*.jar" /></fileset> </path> <property name="debuglevel" value="source,lines,vars"/> <property name="target" value="1.6"/> <property name="source" value="1.6"/> <target name="init"> <property name="build" value="build/destination/webapp"></property> <property name="src" value="src"></property> <mkdir dir="${build}"/> <mkdir dir="${build}\WEB-INF"/> <mkdir dir="${build}\WEB-INF\classes"/> <mkdir dir="${build}\WEB-INF\lib"/> <copy todir="${build}"> <fileset dir="${basedir}\WebContent"> <include name="WEB-INF/**" /> <include name="**" /> </fileset> </copy> </target> <target name="complie" depends="init"><!--添加源文件内容和编码utf-8 因为默是系统的本地时间--> <javac srcdir="${src}" destdir="${build}/WEB-INF/classes" encoding="utf-8" classpathref="classpath"> </javac> </target> <!--生成war 包结构--> <target name="makewar" depends="complie"> <war warfile="${build}/newbssqyl.war" webxml="${build}/WEB-INF/web.xml"> <lib dir="${build}/WEB-INF/lib"> <include name="**" /> </lib> <classes dir="${build}/WEB-INF/classes"/> <fileset dir="${build}"/> </war> </target> </project>
?
?
?
?