ant的build.xml模板

本文详细介绍了如何使用Ant构建工具来自动化构建Java项目,包括编译源代码、打包、生成文档、执行代码规范检查和运行测试等关键步骤。

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

<?xml version="1.0" encoding="UTF-8"?>
<project name="java-util" default="all" basedir=".">

<property name="project-name" value="${ant.project.name}"/>
<property name="version" value="1.0.0"/>
<property name="src.dir" value="src"/>

<!-- doc directory -->
<property name="doc.dir" value="doc"/>
<property name="doc.api.dir" value="${doc.dir}/api"/>

<property name="lib.dir" value="lib"/>
<property name="dist.dir" value="dist"/>
<property name="build.dir" value="build"/>
<property name="build.class.dir" value="${build.dir}/classes"/>

<!-- test directory -->
<property name="test.src.dir" value="test"/>
<property name="test.class.dir" value="${build.dir}/test"/>
<property name="test.report.dir" value="${build.dir}/report"/>
<property name="test.report.html.dir" value="${build.dir}/report/html"/>


<!-- checkstyle configuration -->
<property name="checkstyle.config" value="checkstyle.xml"/>
<taskdef resource="checkstyletask.properties"
classpath="${lib.dir}/checkstyle-all-3.1.jar"/>


<!-- 输出文档 -->
<property name="javadoc.package" value="com.*"/>


<!-- classpath -->
<path id="main-classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="test-classpath" cache="true">
<path refid="main-classpath"/>
<pathelement location="${build.class.dir}"/>
</path>

<!-- init target -->
<target name="init">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.class.dir}"/>
<mkdir dir="${dist.dir}"/>
<tstamp/>
<echo message="begin ant task at : ${DSTAMP}-${TSTAMP}"></echo>
</target>

<target name="all" depends="test,jar,doc,checkstyle"/>

<!-- 编译源文件 -->
<target name="compile" depends="init">
<mkdir dir="${build.class.dir}"/>

<javac destdir="${build.class.dir}" includeantruntime="on" deprecation="on">
<src path="${src.dir}"/>
<classpath refid="main-classpath"/>
</javac>
</target>

<!-- 打包文件 -->
<target name="jar" depends="compile">
<jar jarfile="${dist.dir}/${project-name}-${version}-${DSTAMP}-${TSTAMP}.jar" basedir="${build.class.dir}">
<include name="**/*.class"/>
</jar>
</target>

<!-- 产生javadoc -->
<target name="doc" depends="init">
<mkdir dir="${doc.dir}"/>
<mkdir dir="${doc.api.dir}"/>

<javadoc packagenames="${javadoc.package}" sourcepath="${src.dir}"
private="yes" defaultexcludes="yes" destdir="${doc.api.dir}">
<classpath refid="main-classpath"/>
</javadoc>
</target>

<!-- 编译Junit 相关测试文件 -->
<target name="compile-test" depends="compile">
<mkdir dir="${test.class.dir}"/>

<javac destdir="${test.class.dir}" includeantruntime="on" deprecation="on">
<src path="${test.src.dir}"/>
<classpath refid="test-classpath"/>
</javac>
</target>

<!-- 运行checkstyle检查代码规范 -->
<target name="checkstyle" depends="init">
<checkstyle config="${checkstyle.config}">
<fileset dir="${src.dir}" includes="**/*.java"/>
<formatter type="plain"/>
<formatter type="xml" toFile="${dist.dir}/checkstyle_errors.xml"/>
</checkstyle>
</target>

<!-- 运行junit -->
<target name="test" depends="compile-test">
<mkdir dir="${test.report.dir}"/>
<mkdir dir="${test.report.html.dir}"/>

<junit printsummary="yes" haltonfailure="yes">
<classpath refid="test-classpath"/>

<formatter type="plain"/>

<!-- test name="com.TestClassTest" haltonfailure="no" outfile="result"/ -->

<batchtest todir="${test.report.dir}">
<fileset dir="${test.class.dir}" includes="**/Test*.class" />
</batchtest>
</junit>
<junitreport todir="${test.report.dir}" >
<fileset dir="${test.report.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${test.report.html.dir}" />
</junitreport>
</target>

<!-- 清除产生的类、junit相关类、文档 -->
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${doc.api.dir}"/>
</target>

<!-- 清除所有输出结果 -->
<target name="cleanall" depends="clean">
<delete dir="${doc.dir}"/>
<delete dir="${dist.dir}"/>
</target>
</project>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值