⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 anttask.html

📁 JSP页面代码排错
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html><head>      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">   <title>Chapter&nbsp;6.&nbsp;Using the FindBugs&#8482; Ant task</title><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="FindBugs&#8482; Manual"><link rel="up" href="index.html" title="FindBugs&#8482; Manual"><link rel="prev" href="gui.html" title="Chapter&nbsp;5.&nbsp;Using the FindBugs GUI"><link rel="next" href="eclipse.html" title="Chapter&nbsp;7.&nbsp;Using the FindBugs&#8482; Eclipse plugin"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&nbsp;6.&nbsp;Using the <span class="application">FindBugs</span>&#8482; <span class="application">Ant</span> task</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="gui.html">Prev</a>&nbsp;</td><th width="60%" align="center">&nbsp;</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="eclipse.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="anttask"></a>Chapter&nbsp;6.&nbsp;Using the <span class="application">FindBugs</span>&#8482; <span class="application">Ant</span> task</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="anttask.html#d0e1200">1. Installing the <span class="application">Ant</span> task</a></span></dt><dt><span class="sect1"><a href="anttask.html#d0e1238">2. Modifying build.xml</a></span></dt><dt><span class="sect1"><a href="anttask.html#d0e1309">3. Executing the task</a></span></dt><dt><span class="sect1"><a href="anttask.html#d0e1334">4. Parameters</a></span></dt></dl></div><p>This chapter describes how to integrate <span class="application">FindBugs</span> into a build scriptfor <a href="http://ant.apache.org/" target="_top"><span class="application">Ant</span></a>, which is a popular Java buildand deployment tool.  Using the <span class="application">FindBugs</span> <span class="application">Ant</span> task, your build script canautomatically run <span class="application">FindBugs</span> on your Java code.</p><p>The <span class="application">Ant</span> task was generously contributed by Mike Fagan.</p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1200"></a>1.&nbsp;Installing the <span class="application">Ant</span> task</h2></div></div></div><p>To install the <span class="application">Ant</span> task, simply copy <code class="filename"><em class="replaceable"><code>$FINDBUGS_HOME</code></em>/lib/findbugs-ant.jar</code>into the <code class="filename">lib</code> subdirectory of your <span class="application">Ant</span> installation.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>It is strongly recommended that you use the <span class="application">Ant</span> task with the versionof <span class="application">FindBugs</span> it was included with.  We do not guarantee that the <span class="application">Ant</span> task Jar filewill work with any version of <span class="application">FindBugs</span> other than the one it was included with.</p></td></tr></table></div><p></p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1238"></a>2.&nbsp;Modifying build.xml</h2></div></div></div><p>To incorporate <span class="application">FindBugs</span> into <code class="filename">build.xml</code> (the build scriptfor <span class="application">Ant</span>), you first need to add a task definition.  This should appear as follows:</p><pre class="screen">  &lt;taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/&gt;</pre><p>The task definition specifies that when a <code class="literal">findbugs</code> element isseen in <code class="filename">build.xml</code>, it should use the indicated class to execute the task.</p><p>After you have added the task definition, you can define a targetwhich uses the <code class="literal">findbugs</code> task.  Here is an examplewhich could be added to the <code class="filename">build.xml</code> for theApache <a href="http://jakarta.apache.org/bcel/" target="_top">BCEL</a> library.</p><pre class="screen">  &lt;property name="findbugs.home" value="/export/home/daveho/work/findbugs" /&gt;  &lt;target name="findbugs" depends="jar"&gt;    &lt;findbugs home="${findbugs.home}"              output="xml"              outputFile="bcel-fb.xml" &gt;      &lt;auxClasspath path="${basedir}/lib/Regex.jar" /&gt;      &lt;sourcePath path="${basedir}/src/java" /&gt;      &lt;class location="${basedir}/bin/bcel.jar" /&gt;    &lt;/findbugs&gt;  &lt;/target&gt;</pre><p>The <code class="literal">findbugs</code> element must have the <code class="literal">home</code>attribute set to the directory in which <span class="application">FindBugs</span> is installed; in other words,<em class="replaceable"><code>$FINDBUGS_HOME</code></em>.  See <a href="installing.html" title="Chapter&nbsp;2.&nbsp;Installing FindBugs&#8482;">Chapter&nbsp;2, <i>Installing <span class="application">FindBugs</span>&#8482;</i></a>.</p><p>This target will execute <span class="application">FindBugs</span> on <code class="filename">bcel.jar</code>, which is theJar file produced by BCEL's build script.  (By making it depend on the "jar"target, we ensure that the library is fully compiled before running <span class="application">FindBugs</span> on it.)The output of <span class="application">FindBugs</span> will be saved in XML format to a file called<code class="filename">bcel-fb.xml</code>.An auxiliary Jar file, <code class="filename">Regex.jar</code>, is added to the aux classpath,because it is referenced by the main BCEL library.  A source path is specifiedso that the saved bug data will have accurate references to the BCEL source code.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1309"></a>3.&nbsp;Executing the task</h2></div></div></div><p>Here is an example of invoking <span class="application">Ant</span> from the command line, using the <code class="literal">findbugs</code>target defined above.</p><pre class="screen">  <code class="prompt">[daveho@noir]$</code> <span><strong class="command">ant findbugs</strong></span>  Buildfile: build.xml    init:    compile:    examples:    jar:    findbugs:   [findbugs] Running FindBugs...   [findbugs] Bugs were found   [findbugs] Output saved to bcel-fb.xml    BUILD SUCCESSFUL  Total time: 35 seconds</pre><p>In this case, because we saved the bug results in an XML file, we canuse the <span class="application">FindBugs</span> GUI to view the results; see <a href="running.html" title="Chapter&nbsp;4.&nbsp;Running FindBugs&#8482;">Chapter&nbsp;4, <i>Running <span class="application">FindBugs</span>&#8482;</i></a>.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1334"></a>4.&nbsp;Parameters</h2></div></div></div><p>This section describes the parameters that may be specified whenusing the <span class="application">FindBugs</span> task.</p><div class="variablelist"><dl><dt><span class="term"><code class="literal">class</code></span></dt><dd><p>       A nested element specifying which classes to analyze.  The <code class="literal">class</code>       element must specify a <code class="literal">location</code> attribute which names the       archive file (jar, zip, etc.), directory, or class file to be analyzed.  Multiple <code class="literal">class</code>       elements may be specified as children of a single <code class="literal">findbugs</code> element.       </p></dd><dt><span class="term"><code class="literal">auxClasspath</code></span></dt><dd><p>       An optional nested element which specifies a classpath (Jar files or directories)       containing classes used by the analyzed library or application, but which       you don't want to analyze.  It is specified the same way as       <span class="application">Ant</span>'s <code class="literal">classpath</code> element for the Java task.       </p></dd><dt><span class="term"><code class="literal">sourcePath</code></span></dt><dd><p>       An optional nested element which specifies a source directory path       containing source files used to compile the Java code being analyzed.       By specifying a source path, any generated XML bug output will have

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -