Findbugs installation instructions

Source: Internet
Author: User

Findbugs installation instructions

I. Introduction

Findbugs is a static analysis tool that checks class or JAR files and compares bytecode with a set of defect modes to identify possible problems. With this tool, you can analyze the software without actually running the program. It can help improve the quality of code.

Findbugs provides a visual interface for convenient operations. It can also be used as a plug-in for Eclipse, and we use the most plug-in as Eclipse.

Ii. Usage

You can use Findbugs in three ways. You can use the Ant tool through the Swing operation interface provided by Ant and as a plug-in of Eclipse.

1. Ant Tool

Ant is a good Java Automatic Execution tool.

Findbugs officially provides Ant's findbugs operation method. We can use findbugs through 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 the home of findbugs, and use the findbugs task -->

<Target name = "findbugs">

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

Output = "xml: withMessages" outputFile = "generated file">

 

<! -- The above defines the class path for 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 class path"/>

</Findbugs>

</Target>

</Project>

For example, I have a build File for ant operation of findbugs in my blog project.

<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 the home of findbugs, and use the findbugs task -->

<Target name = "findbugs">

<Mkdir dir = "target/findbugs"/>

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

Output = "xml: withMessages" outputFile = "target/findbugs/calendar-fb.xml">

<! -- The above defines the class path for 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 the Ant environment, use ant-f build in the command. xml, or run build directly in Eclipse. an xml file is generated after running. If you want to view findbugs results in Html format, you can set the output attribute to html. In this way, you can use Html to view findbugs results.

2. Provided Swing tools

Ant operations are expert operations. Generally, they are not very familiar with Java and write build. xml files. Compared with Ant, using the Swing tool provided by Findbugs makes Findbugs easier to operate. Run the Findbugs. bat file in the bin folder of the findbugs decompression package.

The Findbugs Swing tool's initial main interface is as follows:

Before analyzing a project, you must create a new project for analysis. Select File> Create

The page for creating a new project is displayed, for example:

Then add the class package and directory to be analyzed (you can select the folder where the compiled class is located or the generated jar package ), add the folder where the helper class is located and the folder where the source file is located (the folder where the java file is located ). Click Finish to create a project for analysis.

After a project is created, the project is automatically parsed.

After resolution:

On the left is the tree structure list of defects. Click a Bug to display the source file and location of the Bugs in the interface on the right.

2.3 Findbugs Eclipse plug-in

The Findbugs plug-in of Eclipse can be used to integrate Findbugs into Eclipse.

2.3.1 install Findbugs Eclipse plug-in

1. Online Installation

Installation address: http://findbugs.cs.umd.edu/eclipse

2. Offline Installation

Download the Findbugs plug-in, put it in the plusin folder under Eclipse, and then restart Eclipse

2.3.2 use of Findbugs Eclipse plug-in

After the Findbugs plug-in is installed. Right-click the project you want to check and choose Find Bugs> Find Bugs to check.

To View bugs detected by Findbugs, choose Windows menu> Show View> Bug Explorer to open the Bug Explorer panel.

To view detailed information about a Bug, choose Windows> Open Perspective and select FindBugs to Open the Properties panel of FindBugs, you can see the most detailed Bugs information in this panel.

For more information about FindBugs, click here.
FindBugs: click here

This article permanently updates the link address:

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.