Generating Project Documentation

If you are developing a Java application or library, you might want to generate JavaDoc.

How do I do that?

Simply execute the javadoc goal and Maven will generate project documentation. Here is the output of the execution of the javadoc goal:

C:\dev\mavenbook\code\genapp\test-application>maven javadoc
 _ _  _ _
|  \/  |_ _ _Apache_ _ _ _ _
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\_ _,_|\_/\_ _ _|_||_|  v. 1.0.2
  
build:start:
  
xdoc:init:
  
maven-javadoc-plugin:report:
    [mkdir] Created dir: C:\dev\mavenbook\code\genapp\test-application\target\
javadoc\src
    [javadoc] Generating Javadoc
    [javadoc] Javadoc execution
    [javadoc] Loading source files for package mdn.testapp...
    [javadoc] Constructing Javadoc information...
    [javadoc] Standard Doclet version 1.5.0_01
    [javadoc] Building tree for all the packages and classes...
    [javadoc] Generating C:\dev\mavenbook\code\genapp\test-application\target\docs\apidocs\
constant-values.html...
    [javadoc] Copying file C:\Documents and Settings\tobrien\.maven\cache\
maven-javadoc-plugin-1.7\plugin-resources\stylesheet.css to file C:\dev\mavenbook\code\
genapp\test-application\target\docs\apidocs\stylesheet.css...
    [javadoc] Building index for all the packages and classes...
    [javadoc] Building index for all classes...
    [delete] Deleting directory C:\dev\mavenbook\code\genapp\test-application\target\
javadoc\src
BUILD SUCCESSFUL
Total time: 7 seconds

Once this goal has been executed, JavaDoc is available in test-application/target/docs/apidocs.

What just happened?

Once again, Maven did all of the heavy lifting. You wanted JavaDoc, you told Maven to generate JavaDoc, end of story. Note that you didn't need to tell Maven anything about the project; it just "knew" what to do. Much of Maven is this straightforward; after you tell Maven about your project there isn't much more you need to do. It handles the details.

Get Maven: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.