`
lxiaodao
  • 浏览: 119695 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

项目工程完整ANT build脚本

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

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>



  • 大小: 12.5 KB
1
0
分享到:
评论
2 楼 lxiaodao 2010-01-15  
静态检查三个工具任意选择,我知道有公司三个工具都用起来了的,代码质量起码让人比较放心。
JUNIT加进去很容易,脚本里面只是注释了。
1 楼 scholers 2010-01-14  
不错,
静态检查的MS太多了吧?

最好能整合进去JUNIT单元测试,作为动态检查的一种。

相关推荐

    ant build脚本代码

    ant build脚本代码,自动化多渠道打包,自定义任务打包 具体看一下这篇博客 http://blog.csdn.net/lsmfeixiang/article/details/49681583

    android ant build脚本代码

    ant build脚本代码,自动化多渠道打包,自定义任务打包 具体看一下这篇博客 http://blog.csdn.net/lsmfeixiang/article/details/49681583

    java项目ant打包脚本

    java项目ant打包脚本,包括环境变量设置,打包脚本等信息,共有三个文件 ant.bat、build.xml、setEnv.cmd

    jenkins+ant的build脚本

    用于jenkins+ant部署jmeter脚本,用于jenkins+ant部署jmeter脚本,

    gwt_ant_build脚本研习

    gwt_ant_build脚本研习 目录 build.xml源文件 构建工程war的分析 自定义的build工程文件

    ant脚本-build.xml

    ant脚本例子,一个build.xml模板, 修改后直接运行。

    ant的build构建脚本

    ant脚本构建工具,有详细的注释、用于构建程序war包,执行编译、修改、拷贝、远程上传程序war包、远程发布程序、远程重启服务器(tomcat)

    ant的build文件说明

    实际开发中的ant编译脚本代码,拥有完善的结构,只需要修改开始几个字段即可使用。

    jmeter+ant 持续集成build.xml文件

    jmeter+ant 持续集成build.xml文件,直接使用ant命令执行jmeter脚本文件,得到图形测试报告

    常用的ANT蚂蚁脚本

    xdocet ant 生成HIBERNATE映射文件。 部署EJB项目。

    ant+jenkins-build.xml

    jmeter+ant+jenkins---build.xml文件,下载运行即可成功

    Ant脚本打包Android程序的demo 多渠道及第三方JAR打包

    build_with_bat是基于bat脚本实现的。 build是在build_with_bat的基础上实现的,主要是在compile和dex部分增加了第三jar的打包。 build_mulity_channel是多渠道打包脚本。该脚本需要ant-contrib-1.0b3.jar的支持。...

    ant的基本配置说明

    Ant 是著名Java开源组织Apache的一个项目,是一个基于java的build工具。它可以使你通过ant脚本语言,自动你的项目拷贝到某个目录,发布项目,或者生成一些代码,执行SQL语言。总之它可以帮助你完成项目开发中除了...

    Ant下常用的Web项目构建脚本

    通常利用Ant工具来对程序源代码进行编译(当然也可以利用IDE工具编译),通常build.xml文件执行默认“compile”任务来完成编译过程。

    Jmeter+ant编译文件build.xml

    ant运行jmeter脚本的build.xml文件

    jmeter所需ant执行脚本

    配合ant使用,可以让jmeter飞起来,文件中对生成的文件进行了备份归档整理,同时调用两个测试报告模版,让功能更加强大

    Ant脚本打包Android程序的demo(含打包第三方jar)

    Ant脚本打包Android程序的demo(含打包第三方jar)。 build_with_bat是基于bat脚本实现的。 build是在build_with_bat的基础上实现的,主要是在compile和dex部分增加了第三jar的打包。

    apache-ant-1.9.3-src.tar

    每个ant脚本(缺省叫build.xml)中设置了一系列任务(target):比如对于一个一般的项目可能需要有以下任务。 * 任务1:usage 打印本脚本的帮助信息(缺省) * 任务2:clean 清空初始化环境 * 任务3:javadoc &lt;-- ...

    react-admin:基于antdesign的管理后台项目

    Ant Design Pro提供了一些有用的脚本,可帮助您快速启动和构建Web项目,代码样式检查和测试。 package.json提供的脚本。 修改或添加其他脚本是安全的: 开始项目 npm start 建立项目 npm run build 检查代码样式 ...

    open-deploy-iib-buildscripts:IIB 部署 ANT 脚本

    open-deploy-iib-buildscripts IIB 部署 ANT 脚本

Global site tag (gtag.js) - Google Analytics