Findbugs installation instructions
Blog type:
- Software management
Eclipseantswingxmlwindows 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.