1. Download and install ant, findbugs
Download ant, findbugs the latest compressed package to the appropriate location on the local disk, such as:
D:\Program files\apache-ant-1.9.7
D:\Program files\findbugs-3.0.1
2. Configure Environment variables
3. Writing Build.xml
<?XML version= "1.0" encoding= "UTF-8"?><Projectname= "Hsacct"> <PathID= "Findbugs.path"> <Filesetdir= "D:/program files/findbugs-3.0.1"> <includename= "**/*.jar" /> </Fileset> </Path> <Taskdefname= "FindBugs"ClassName= "Edu.umd.cs.findbugs.anttask.FindBugsTask"Classpathref= "Findbugs.path" /> < Propertyname= "Findbugs.home"value= "D:/program files/findbugs-3.0.1" /> <Targetname= "FindBugs"> <findbugsHome= "D:/program files/findbugs-3.0.1"Jvmargs= "-xmx1024m"Output= "html"OutputFile= "D:/program files/findbugs-3.0.1/mytest.html"> <class Location= "D:/offsite/sources/mytest_main/mytest-account" /> <class Location= "D:/OFFSITE/SOURCES/MYTEST_MAIN/MYTEST-ACPT" /> <class Location= "D:/offsite/sources/mytest_main/mytest-act-account" /> <class Location= "D:/offsite/sources/mytest_main/mytest-act-common" /> <class Location= "D:/offsite/sources/mytest_main/mytest-arch" /> <class Location= "D:/offsite/sources/mytest_main/mytest-autotask" /> <class Location= "D:/offsite/sources/mytest_main/mytest-bankacct" /> <class Location= "D:/offsite/sources/mytest_main/mytest-cert" /> <class Location= "D:/OFFSITE/SOURCES/MYTEST_MAIN/MYTEST-CSDC" /> <class Location= "D:/offsite/sources/mytest_main/mytest-elig" /> <class Location= "D:/offsite/sources/mytest_main/mytest-ofsecu" /> <class Location= "D:/offsite/sources/mytest_main/mytest-preengage" /> <class Location= "D:/offsite/sources/mytest_main/mytest-prod" /> <class Location= "D:/OFFSITE/SOURCES/MYTEST_MAIN/MYTEST-SDK" /> <class Location= "D:/offsite/sources/mytest_main/mytest-system" /> <AuxclasspathPath= "D:/program Files/findbugs-3.0.1/lib/findbugs-ant.jar" /> <Auxclasspath> <Filesetdir= "D:/offsite/sources/mytest_main/mytest/target/mytest-1.1.0/web-inf/lib"includes= "**/*.jar" /> </Auxclasspath> <SourcePathPath= "D:/offsite/sources/mytest" /> </findbugs> </Target></Project>
4. Generate reports
Open the command line and go to the folder where the Build.xml file is located, and type the Ant findbugs command to enter.
5. Partial Attribute parameter description
a detailed description of the FindBugs task is as follows:
classThe nested element specifies the class to parse. This element must specify a location property whose name is the archive file (Jar,zip, etc.), the directory, or the class file.
You can specify multiple class elements for a findbugs element.
AuxclasspathAn optional nested element that specifies the class referenced by the class to be parsed, but does not parse the referenced class.
SourcePathAn optional nested element that specifies the directory of the Java source code.
HomeThe required properties for the FindBugs installation directory.
quieterrorsOptional Boolean property. If true, reports serious parsing errors and missing classes. False by default.
ReportlevelAn optional property. Specifies the priority level. If it is low, then report all bugs, if medium (the default), report medium and high priority bugs.
OutputOptional properties, setting output format
stylesheetAn optional attribute that specifies the style sheet to use when generating HTML.
SortAn optional attribute that, if the output property is set to text, specifies whether the output is sorted according to class, which defaults to true.
OutputFileAn optional attribute that specifies the output file.
DebugOptional Boolean property, whether to print logs during parsing. The default value is False.
effortSet the level of analysis work, which can be min, default, and Max.
ConservespaceThe same function as min effort.
WorkhardThe same functionality as Max effort.
VisitorsOptional attribute, specifying a comma-delimited list that specifies the detectors to run.
omitvisitorsOptional attribute, ignoring detectors. The visitors property is similar, except that it does not specify which detectors to run.
ExcludeFilterAn optional attribute that specifies the excluded filter.
includefilterAn optional attribute that specifies the containing filter.
ProjectFileAn optional attribute that specifies the name of the project.
JvmargsAn optional attribute that specifies the JVM variable.
SystempropertySystem Properties.
TimeoutOptional attribute that specifies the time of the supermarket, which defaults to 600,000 milliseconds, or 10 minutes.
FailOnErrorAn optional property that specifies whether to stop the build process when an exception is run findbugs, which defaults to false.
ErrorpropertyOptional property, if an error occurs while running FindBugs, the value of the specified property is true.
WarningspropertyAn optional property that specifies a value of true if a warning occurs when FindBugs is run.
6. Issues that may be encountered
Because the project is relatively large, a blank HTML file may be generated during the export of HTML. At this point the Jvmargs parameter value is adjusted, such as jvmargs= "-xmx1024m".
Ant+findbugs Scan Code Generation report