阅读更多
“FindBugs是一个静态分析工具,它检查类或者 JAR 文件”(详见[url]http://www-900.ibm.com/developerWorks/cn/java/j-findbug1/ [/url])
结合ant的使用,可以。
运行结束后可以使用FindBugs的GUI查看输出报告:findbugs_report.xml
build.xml:
<?xml version="1.0" encoding="utf-8"?>
<project name="test" default="clean" basedir=".">
<description>This Is A Test</description>
<property name="src" location="src"/>
<property name="dist" location="dist"/>
<property name="lib" location="D:\useablelib"/>
<property name="findbugs.home" value="D:\findbugs-0.8.6" />
<!--define new task to use findbugs-->
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/>
<path id="classpath">
<pathelement path="${classpath}"/>
<pathelement path="${lib}"/>
<fileset dir="${lib}" includes="*.jar"/>
</path>
<target name="init" description="initialize">
<mkdir dir="${dist}"/>
</target>
<target name="compile" depends="init" description="prepare item for compile">
<javac srcdir="${src}" destdir="${dist}" deprecation="Yes">
<classpath refid="classpath"/>
</javac>
</target>
<target name="findbugs" depends="compile" description="use findbugs to find out bugs">
<echo message="use findbugs"></echo>
<findbugs home="${findbugs.home}"
output="xml"
outputFile="findbugs_report.xml" >
<sourcePath path="${src}"></sourcePath>
<class location="${dist}" />
</findbugs>
</target>
<target name="clean" depends="findbugs" description="clean up">
<delete dir="${dist}"/>
</target>
</project>