3. 从源码构建 FindBugs™
本章介绍如何从源代码构建 FindBugs。除非你打算修改 FindBugs,否则建议直接跳到下一章。
1. 前提条件
要从源代码编译 FindBugs,你需要具备以下条件:
- FindBugs 源码分发包
- JDK 1.5.0 或更高版本
- Apache Ant 1.6.3 或更高版本
![]() | 警告 |
|---|---|
Redhat Linux 系统上作为 /usr/bin/ant 提供的 Ant 版本无法用于编译 FindBugs。我们建议你从 Ant 网站下载并安装 Ant 的二进制分发包。运行 Ant 时,请确保 JAVA_HOME 环境变量指向你安装 JDK 1.5(或更高版本)的目录。 |
如果你希望能够生成 FindBugs 文档的格式化版本,还需要以下软件:
- DocBook XSL 样式表。将 FindBugs 手册转换为 HTML 格式时必需。
- Saxon XSLT 处理器。(同样为将 FindBugs 手册转换为 HTML 所必需。)
2. 解压源码分发包
下载源码分发包后,你需要将其解压到一个工作目录中。典型的命令如下:
$ unzip findbugs-3.0.1-source.zip3. 修改 local.properties
如果你打算构建 FindBugs 文档,就需要修改 Ant 用于构建 FindBugs 的 build.xml 文件所使用的 local.properties 文件。如果你不需要构建 FindBugs 文档,则可以忽略这个文件。
local.properties 会覆盖 build.properties 文件中的定义。build.properties 文件的内容大致如下:
# User Configuration:
# This section must be modified to reflect your system.
local.software.home =/export/home/daveho/linux
# Set this to the directory containing the DocBook Modular XSL Stylesheets
# from http://docbook.sourceforge.net/projects/xsl/
xsl.stylesheet.home =${local.software.home}/docbook/docbook-xsl-1.71.1
# Set this to the directory where Saxon (http://saxon.sourceforge.net/)
# is installed.
saxon.home =${local.software.home}/java/saxon-6.5.5
xsl.stylesheet.home 属性指定你安装 DocBook 模块化 XSL 样式表 的目录的完整路径。只有在需要生成 FindBugs 文档时才需要指定该属性。
saxon.home 属性是你安装 Saxon XSLT 处理器 的目录的完整路径。只有在需要生成 FindBugs 文档时才需要指定该属性。
4. 运行 Ant
在解压源码分发包、确认已安装 Ant、修改 build.properties(可选)并配置好相关工具(如 Saxon)之后,你就可以开始构建 FindBugs 了。调用 Ant 只需运行以下命令
$ ant target其中 target 是以下之一:
build
此目标编译 FindBugs 的代码。它是默认目标。
docs
此目标格式化文档。(作为副产物,它还会编译部分源代码。)
runjunit
此目标编译并运行 FindBugs 中包含的内部 JUnit 测试。如果有任何单元测试失败,它会打印一条错误消息。
bindist
构建 FindBugs 的二进制发行版。该目标会同时创建 .zip 和 .tar.gz 归档文件。
运行 Ant 命令后,在输出了一些有关 Ant 正在执行的任务的其他消息之后,你应该会看到类似如下的输出:
BUILD SUCCESSFUL
Total time: 17 seconds
5. 从源码目录运行 FindBugs™
FindBugs 的 Ant 构建脚本经过这样的设计:在构建了 build 目标之后,工作目录的组织方式与二进制发行版完全相同。因此,第 4 章 运行 FindBugs™ 中关于运行 FindBugs 的说明同样适用于源码发行版。
评论
登录后参与评论
KnowForge![\[Warning\]](https://findbugs.sourceforge.net/manual/warning.png)