项目工程完整ANT build脚本

完整的ant脚本,包含javac、javadoc、checkstyle、findbugs等等脚本命令。如果你还没有完整的ant脚本来管理工程,请参考使用此脚本,肯定给项目的管理带来很多好处。Ant脚本在手,管理工具不求。
静态代码检查工具三剑客,Checkstyle、findbugs、pmd的task都包含了,呵呵。请注意看清楚命令中的版本,这三个工具都可以从网络下载。
目录的结构个人喜好不一样,如果你的目录结构和我的不一致,请修改脚本中对应的参数。
目录结构说明图:

[img]http://dl.iteye.com/upload/attachment/179674/30213431-9e7a-3401-bcc6-88bd4cd96b67.jpg[/img]
Ant脚本如下:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Framework" default="build" basedir=".">
<!--
src:java source code
test:java test source code folder
resources:configuration file folder

dist:The jar and classes.
-classes

report:Test result report and checkstyle report folder.
-checkstyle
-tests
-findBugs

doc:Do not delete the folder.
Javadoc and checksyle configuration files.
-javadoc
-pmd
-codestyle
-findBugs
-->

<property name="src.dir" value="${basedir}/src"/>

<property name="lib.dir" value="${basedir}/WebRoot/WEB-INF/lib"/>
<property name="test.lib.dir" value="${basedir}/testlib"/>

<property name="dist.dir" value="${basedir}/dist"/>
<property name="dist.classes" value="${dist.dir}/classes"/>

<property name="docs.dir" value="${basedir}/doc"/>
<property name="report.dir" value="${basedir}/report"/>

<property name="jar.file" value="framework-core-1.0.jar"/>

<!-- All Need jar-->
<path id="classpath">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
<fileset dir="${test.lib.dir}">
<include name="*.jar" />
</fileset>
</path>

<target name="clean">
<delete dir="${dist.dir}" excludes="**/.svn" />
<delete dir="${report.dir}" excludes="**/.svn" />
<delete dir="${dist.classes}" excludes="**/.svn" />
</target>

<target name="prepare" depends="clean" description="Create the target directories">
<mkdir dir="${dist.dir}" />
<mkdir dir="${report.dir}" />
<mkdir dir="${report.dir}/tests" />
<mkdir dir="${report.dir}/checkstyle" />
<mkdir dir="${dist.classes}" />

</target>
<!--
=================================src下面java文件到指定class目录=====================
请注意一些配置文件需要全部拷贝过去,不要遗漏
-->
<target name="compile" depends="prepare" description="========WEBFUSW COMPILE=====">

<javac encoding="utf-8" destdir="${dist.classes}" debug="true">
<src path="${src.dir}" />

<classpath>
<path refid="classpath" />
</classpath>
</javac>
<copy todir="${dist.classes}">
<fileset dir="resources">
<include name="**/*.*" />
</fileset>

</copy>

</target>

<!--================================= 产生javadoc===================== -->
<target name="javadoc">
<mkdir dir="${docs.dir}/javadoc" />
<javadoc encoding="utf-8" sourcepath="${src.dir}" destdir="${docs.dir}/javadoc">
<classpath refid="classpath"/>
</javadoc>
<echo message="...........Javadoc command complete...."/>
</target>
<!--================================= test and create report===================== -->
<!--
<target name="tests" depends="compile">
<junit printsummary="on" fork="true" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
<classpath>
<fileset dir="${classpath}" includes="**/*.jar" />
<pathelement path="${dist.classes}" />
</classpath>
<formatter type="xml" />
<batchtest todir="${report.dir}/tests">
<fileset dir="${dist.classes}">
<include name="**/*Test.*" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${report.dir}/tests">
<fileset dir="${report.dir}/tests">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${report.dir}/tests" />
</junitreport>
</target>
-->
<!--
================================= create checkstyle report=====================
Please notify:modify the param of checkstyle-frames-errors.xsl and checkstyle-frames.xsl files as below
<xsl:param name="output.dir" select="'report/checkstyle'"/>
-->

<taskdef resource="checkstyletask.properties" classpath="${docs.dir}/checkstyle/checkstyle-all-5.0.jar"/>
<target name="checkstyle" depends="prepare" description="Generates a report of code convention violations.">
<mkdir dir="${report.dir}/checkstyle" />
<checkstyle
config="${docs.dir}/checkstyle/checkstyle_checks.xml"
failOnViolation="false">
<fileset dir="${src.dir}" includes="**/*.java" excludes="**/*Test.java" />
<formatter type="xml" toFile="${report.dir}/checkstyle/checkstyle_result.xml" />
</checkstyle>

<style in="${report.dir}/checkstyle/checkstyle_result.xml" out="${report.dir}/checkstyle/blank_report.html" style="${docs.dir}/checkstyle/checkstyle-frames-errors.xsl"/>

</target>
<!--
================================= findBugs report=====================
Run Error:javaheap is over,need modify the configure.
-->

<taskdef name="findbugs" classpath="${docs.dir}/findBugs/findbugs.jar" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/>
<property name="findbugs.home" value="${docs.dir}/findbugs" />

<target name="findbugs" description="Running findBugs......">
<mkdir dir="${report.dir}/findBugs" />

<findbugs home="${findbugs.home}"
output="xml"
outputFile="${report.dir}/findBugs/findBugs-report.xml" jvmargs="-Xmx512m">

<auxClasspath path="${docs.dir}/findBugs/jakarta-regexp-1.5.jar" />

<!-- dist.classes
<class location="${docs.dir}/findBugs/bcel.jar" />
-->
<class location="${dist.classes}" />
<!-- show findBugs -->
<sourcePath path="${src.dir}" />

</findbugs>
</target>
<!--
================================= PMD report=====================
PMD means from pmd.sourceforge.net:
Pretty Much Done.
Programming Mistake Detector.
<ruleset>basic</ruleset>
-->
<target name="pmd" description="Running PMD......">
<mkdir dir="${report.dir}/pmd" />
<taskdef name="pmd" classpath="${docs.dir}/pmd/pmd-4.2.5.jar" classname="net.sourceforge.pmd.ant.PMDTask"/>
<pmd shortFilenames="true">
<ruleset>${docs.dir}/pmd/springside3_ruleset.xml</ruleset>

<formatter type="html" toFile="${report.dir}/pmd/pmd_report.html" linkPrefix="../../doc/javadoc/"/>

<formatter type="xml" toFile="${report.dir}/pmd/pmd.xml" />
<fileset dir="${src.dir}">
<!--<include name="java/lang/*.java"/>-->
</fileset>
</pmd>
</target>

<!--
================================= JAR Task=====================
checkstyle,pmd,javadoc,compile
${dist.classes}
-->
<target name="jar" depends="compile,checkstyle,pmd,findbugs">
<jar destfile="${dist.dir}/${jar.file}">
<fileset dir="${dist.classes}">
<include name="**/*.class"/>
<include name="**/*.xml" />
<include name="**/*.conf" />
<include name="**/*.sql" />
<include name="**/*.properties" />
<include name="**/*.dtd" />
<exclude name="**/*Test.class" />
<exclude name="**/Test*.class" />
</fileset>

</jar>
</target>
<target name="build" depends="jar,javadoc" description="build project" />
</project>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值