Generating Javadocs for a site

Documentation for Java projects is created using Javadocs. Maven provides support not only to generate Javadocs, but also to publish them as part of the site. Plugins configured within the reporting element will generate content for the site. When they are configured within the build element, they can generate reports independent of site.

How to do it...

Use the following steps to generate Javadocs for a site:

  1. Open the Maven project project-with-documentation.
  2. Add the following section in the pom.xml file:
    <reporting>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>2.10.1</version>
        </plugin>
      </plugins>
    </reporting>
  3. Run the following command:
    mvn site
    
  4. See the report generated:
    How to do it...
  5. Click on the JavaDocs link:
    How to do it...

How it works...

We added the Javadoc plugin to the reporting section of pom. When the Site plugin runs, it examines this section and runs the reports configured there. In this case, it found javadoc and ran the relevant plugin to generate the Javadoc reports for the project.

Maven links the report from the site page in the Project Reports section.

There's more...

What if we do not want to document the test classes, but only the source? We can configure the plugin to do this by performing the following steps:

  1. Add the following code to the reporting section where we set the value of report element to javadoc:
            <reportSets>
              <reportSet>
                <reports>
                  <report>javadoc</report>
                </reports>
               </reportSet>
            </reportSets>
  2. Run the following command:
    mvn site
    
  3. Open the resulting Site web page. Only the JavaDocs link is present on the site. The Test JavaDocs link is no longer present.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.165.115