Ant集成应用标准模板

本文详细介绍了一个使用Ant构建工具的示例项目。通过解析build.xml文件,展示了如何设置项目属性、定义构建目标,以及进行编译、打包等操作。此外,还介绍了如何生成javadoc文档和执行单元测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

build.xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!-- ================================================ -->
<!--  Sample buildfile for jar components             -->
<!--                                                  -->
<!-- ================================================ -->
<project name="sample" default="build">
 <property file="build.properties" />
 <!--   webapp路径 -->
 <property name="webapp.dir" value="${basedir}" />
 <!-- WebLogic路径
 <property name="weblogic.home"/>
 -->
 <!-- class文件编译路径 -->
 <property name="build.dir" location="${webapp.dir}/WEB-INF/classes" />
 <!-- war发布路径 -->
 <property name="dist.dir" location="${webapp.dir}/dist" />
 <!-- 测试报告目录 -->
 <property name="report.dir" location="${webapp.dir}/report" />
 <!--   jar包路径 -->
 <property name="lib.dir" location="${webapp.dir}/WEB-INF/lib">
 </property>
 <!-- 发布应用名称 -->
 <property name="app.name" value="ImageFR" />
 <!-- 发布版本号 -->
 <property name="app.version" value="1.0">
 </property>

 <!-- javadoc路径-->
 <property name="build.javadocs" value="${webapp.dir}/doc" />
 <!-- javadoc的输出包 -->
 <property name="javadoc.packages" value="com.topcheer.*" />
 <!--   java源文件路径 -->
 <path id="build.src">
  <pathelement path="${webapp.dir}/src">
  </pathelement>
  <pathelement path="${webapp.dir}/configuration">
  </pathelement>
 </path>
 <property name="src.dir" refid="build.src">

 </property>
 <!--  classpath路径 -->
 <path id="compile.classpath">
  <fileset file="${lib.dir}/*.jar" />
  <fileset file="${weblogic.home}/server/lib/weblogic.jar" />
 </path>
 
 <!-- =================================================================== -->
 <!-- 准备源文件-->
 <!-- =================================================================== -->
 <target name="init">
  <tstamp />
  <mkdir dir="${dist.dir}">
  </mkdir>
  <mkdir dir="${build.dir}">
  </mkdir>
  <mkdir dir="${report.dir}" />
 </target>

 <!-- =================================================================== -->
 <!-- 编译源文件-->
 <!-- =================================================================== -->
 <target name="build" depends="init,clean" description="compile and jar this component">
  <echo message="build ${app.name}">
  </echo>
  <javac srcdir="${src.dir}" destdir="${build.dir}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">
   <classpath refid="compile.classpath" />
   <!-- 去除测试类

   <exclude name="Test*.java" />
   <exclude name="*Test.java" />
    -->
  </javac>
  <echo message="build completed" />
  <!--
   <mkdir dir="${dist.home}" />
   <jar destfile="${dist.home}/${app.name}.jar" basedir="${build.home}" excludes="**/*UT.class" />
   <echo message="distributed completed" />
  -->
 </target>

 <!-- =================================================================== -->
 <!-- 打war包 -->
 <!-- =================================================================== -->
 <target name="dist" depends="build" description="pack the whole application into a war file">
  <war warfile="${dist.dir}/${app.name}.war" webxml="${webapp.dir}/WEB-INF/web.xml">
   <lib dir="${lib.dir}" />
   <classes dir="${build.dir}" />
   <fileset dir="${webapp.dir}">
    <exclude name="{dist.dir}" />
    <exclude name="./bin" />
    <exclude name="./doc" />
    <exclude name="${src.dir}" />
    <exclude name="./.myeclipse" />
    <exclude name="./logs" />
    <exclude name="./testfiles" />
   </fileset>
  </war>
 </target>


 <!-- =================================================================== -->
 <!-- 产生javadoc api 文档-->
 <!-- =================================================================== -->
 <target name="javadoc" depends="build">
  <mkdir dir="${build.javadocs}" />
  <javadoc packagenames="${javadoc.packages}" sourcepath="${src.dir}" destdir="${build.javadocs}" author="true" version="true" use="true" splitindex="true" windowtitle="${app.name} API" doctitle="${app.name}">
   <classpath refid="compile.classpath" />
  </javadoc>
 </target>

 <!-- =================================================================== -->
 <!-- 清除临时文件-->
 <!-- =================================================================== -->
 <target name="clean">
  <delete dir="${build.dir}" includes="**/*.class" />
  <echo message="${build.dir} has been clean." />
  <delete dir="${dist.dir}" includes="*.war" />
  <delete dir="${report.dir}" includes="*.*" />
  <echo message="${dist.dir} has been clean." />
 </target>


 <!-- =================================================================== -->
 <!-- 执行单元测试-->
 <!-- =================================================================== -->
 <target name="test">
  <junit>
   <classpath refid="compile.classpath" />
   <classpath>
    <pathelement location="${build.dir}" />
   </classpath>

   <formatter type="xml" />
   <test name="test.topcheer.AllTests" haltonfailure="no" outfile="result" />
  </junit>
  <junitreport todir="${report.dir}">
   <fileset dir=".">
    <include name="result.xml" />
   </fileset>
   <report format="noframes" todir="${report.dir}" />
  </junitreport>

 </target>
</project>

<!-- 注:outfile="result"表示输出的结果文件,在产生测试报告时需要用到此文件 -->

 build.propertie文件内容如下:

#WebLogic根路径
weblogic.home=D:/bea/weblogic81

#webapp.dir=
#build.dir=
#dist.dir=
#report.dir=
#lib.dir=
#app.name=
#build.javadocs=
#javadoc.packages=

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值