FindBugs Introduction and use Method

Source: Internet
Author: User

 

1. Introduction

Findbugs is a static analysis tool that examines a class or JAR file to compare bytecode with a set of defect patterns to identify possible problems. With this tool, the software can be analyzed without actually running the program. It can help improve the quality of your code.

FindBugs provides a convenient visual interface and can be used as a plug-in for Eclipse, which we use most often as an eclipse plug-in.

2. How to use

The findbugs can be used in three ways, through the Ant tool, through the swing operator interface provided by Ant and as a plug-in for Eclipse.

2.1 Ant Tools

Ant is a good Java auto-execution tool.

FindBugs officially provides Ant's FindBugs method of operation, and we can use findbugs with such a build.xml file.

<project name= "project name" default= "All" >

<property name= "Findbugs.home" value= "findbugs decompression path"/>

<path id= "Findbugs.path" >

<fileset dir= "findbugs decompression path" >

<include name= "**/*.jar"/>

</fileset>

</path>

<taskdef name= "FindBugs"

Classname= "Edu.umd.cs.findbugs.anttask.FindBugsTask"

classpathref= "Findbugs.path"/>

<!--define FindBugs's home,findbugs task to use--

<target name= "FindBugs" >

<findbugs home= "${findbugs.home}"

output= "Xml:withmessages" outputfile= "generated Files" >

<!--above defines the classpath of FindBugs lookup--

<auxclasspath path= "${findbugs.home}/lib/findbugs-ant.jar"/>

<auxClasspath>

<fileset dir= "Lib"

includes= "*.jar"/>

</auxClasspath>

<sourcepath path= "source file path"/>

<class location= "Generate Classpath"/>

</findbugs>

</target>

</project>

For example, I have a build file for the ant operation of the FindBugs project I put on my blog.

<project name= "Calendar" default= "All" >

<property name= "Findbugs.home" value= ". /.. /findbugs-1.3.8 "/>

<path id= "Findbugs.path" >

<fileset dir= ". /.. /findbugs-1.3.8 ">

<include name= "**/*.jar"/>

</fileset>

</path>

<taskdef name= "FindBugs"

Classname= "Edu.umd.cs.findbugs.anttask.FindBugsTask"

classpathref= "Findbugs.path"/>

<!--define FindBugs's home,findbugs task to use--

<target name= "FindBugs" >

<mkdir dir= "Target/findbugs"/>

<findbugs home= "${findbugs.home}"

output= "Xml:withmessages" outputfile= "Target/findbugs/calendar-fb.xml" >

<!--above defines the classpath of FindBugs lookup--

<auxclasspath path= "${findbugs.home}/lib/findbugs-ant.jar"/>

<auxClasspath>

<fileset dir= "Lib"

includes= "*.jar"/>

</auxClasspath>

<sourcepath path= "src"/>

<class location= "Target/classes"/>

</findbugs>

</target>

</project>

After setting up the ant environment, use ant-f in the command Build.xml, or run the Build.xml file directly in Eclipse, run an XML file, and if you want to see the results of FindBugs in HTML format, you can set the Output property to: HTML. This allows you to see the results of the findbugs through HTML.

2.2 Swing tools provided

Ant operations are expert-level operations, typically for people who are not very familiar with Java, and write build.xml files. Using the Swing tool provided by FindBugs can make findbugs easier than Ant. Run the Findbugs.bat file under the Bin folder in the FindBugs decompression package.

The initial main interface of the FindBugs Swing tool is as follows:

Before analyzing the project, we have to create a new project to analyze, select File--New

Display the new project's interface as:

Then add the class package and directory that you want to analyze (you can choose the folder where the compiled class is located, or you can select the generated jar package), and then add the folder where the auxiliary class resides and the folder where the source file resides (the folder where the Java file resides). Then click Finish to create a project to analyze.

Once the project is established, the project will automatically begin parsing automatically first.

Post-Parse Interface:

The left side is a list of defective tree structures, click on one of the bugs, you can display the bugs source file and its location in the right interface.

2.3 Findbugs Eclipse Plugin

Eclipse's FindBugs plugin to integrate FindBugs into eclipse.

2.3.1 FindBugs's Eclipse plugin installation method

1. Online Installation

Installation Address: Http://findbugs.cs.umd.edu/eclipse

2. Offline installation

Download the FindBugs plugin, put it into the Plusin folder under Eclipse, and then restart Eclipse

2.3.2 FindBugs's Eclipse plugin uses

After installing the FindBugs plugin. Right click on the item you want to check select "Find Bugs", "Find Bugs" to check.

To see what Bugs findbugs checked out, you can open the Bug Explorer panel by choosing Windows menu->show View->bug Explorer.

If you want to see detailed information about a bug, you can choose the Windows menu->open perspective, and then select FindBugs to open the Properties panel for FindBugs. In this panel you can see the most detailed bugs information.

FindBugs Introduction and use Method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.