我目前正在开发一个用 Java 编写的项目,我正在使用 Maven 和 maven-site-plugin 生成一个包含所有相关 JavaDoc、报告等的网站。我同时需要能够转换相同的将文档转换为可读的、类似于书籍的格式。是否有任何脚本或工具可以用来获取网站,并将其转换为格式合理的 PDF 或其他样式,以便可以轻松地以数字形式提供或打印出来?

请您参考如下方法:

maven-pdf-plugin生成项目文档的 PDF。
需要考虑的文档中的两个注释:

Note 1: By default, the PDF plugin generates a PDF document which aggregates all your site documents. If you want to generate each site document individually, you need to add -Daggregate=false in the command line.

Note 2: By default, the PDF plugin uses the FOP implementation. The plugin also supports the iText implementation, you just need to add -Dimplementation=itext in the command line.


您实际上可以在 POM 中指定聚合属性(请参见下面的示例)。
此配置将在 docs 的每个构建上生成 PDF。 profile 处于事件状态(您可以在每次构建时都这样做,但对于您的典型开发周期来说会有点慢:
<profiles> 
  <profile> 
    <id>docs</id> 
    <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-pdf-plugin</artifactId> 
      <version>1.0</version> 
      <executions> 
        <execution> 
          <id>pdf</id> 
          <phase>site</phase> 
          <goals> 
            <goal>pdf</goal> 
          </goals> 
          <configuration> 
            <outputDirectory> 
              ${project.reporting.outputDirectory} 
            </outputDirectory> 
            <aggregate>false</aggregate> 
          </configuration> 
        </execution> 
      </executions> 
    </plugin> 
  </profile> 
</profiles> 
您可以使用 -P docs 在命令行上激活配置文件或使用 activation如果你想要更细粒度的配置。


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!