Findbugs 用Ant脚本扫描bugs生成报告

1.先安装好findbugs插件

2..在工程Project下创建一个文件build.xml

3.编辑build.xml的内容

<!-- 指定项目名和default-->
<project name="ProjectMx" default="findbugs">
	<property name="findbugs.home" value="自己的findbugs的路径,如:D:\eclipse\plugins\edu.umd.cs.findbugs.plugin.eclipse_3.0.1" />
	<path id="findbugs.path">
		<fileset dir="自己的findbugs的路径,如D:\eclipse\plugins\edu.umd.cs.findbugs.plugin.eclipse_3.0.1">
			<include name="**/*.jar" />
		</fileset>
	</path>
 
	<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
		classpathref="findbugs.path" />
	
	<target name="findbugs">
		<mkdir dir="findbugs" />
        <!-- 定义findbugs的home,findbugs的task要使用 -->
        <!-- outputFile是指定生成报告的位置 -->
		<findbugs home="${findbugs.home}" output="html"
			outputFile="findbugs/ProjectMx-findbugs.html">
			<!-- 以上定义findbugs查找的类路径 -->
			<auxClasspath path="${findbugs.home}/lib/findbugs-ant.jar" />
			<auxClasspath>
				<fileset dir="lib" includes="*.jar" />
			</auxClasspath>
 
			<sourcePath path="src" />
			<class location="bin" />
		</findbugs>
	</target>
</project>

 4.在build.xml同个文件夹下,通过cmd运行build.xml. 我写了一个runBuild.bat文件来运行.cmd运行是在这个位置下运行这个命令

ant -f build.xml;

5.运行后会在build.xml指定的outputFile的位置生成报告. runBuild.bat不能直接在ecilpse运行。要在文件位置那里运行

 生成的报告ProjectMx-findbugs.html如下下图:)

Findbugs 用Ant脚本扫描bugs生成报告

Findbugs 用Ant脚本扫描bugs生成报告

 

.....下次看能不能补上 过滤的指定bug类型的 (*^▽^*)