How to Generate JavaDoc Jar file with Maven

This example explains how you can Generate JavaDoc Jar file in your build using Maven. When developing internal libraries for your company it is recommended to automatically generate javadoc jar files. That way other developers in your company who uses your dependencies can look inside the code with a decent IDE. Believe me things can be quite frustrating when they don’t. These JavaDocs can be automatically created by the maven-javadoc plugin which uses the javadoc executable located in $JDK_HOME/bin/ directory.

Create a simple User POJO

Lets create a simple POJO as an example JavaDoc candidate.

 * User object
public class User {

    private Integer id;
    private String username;
    private String password;
    private String email;

     * Creates a new user
     * @param username unique username of the user
     * @param password password of the user
     * @param email email address of the user
    public User(String username, String password, String email) {
        this.username = username;
        this.password = password; = email;

    public Integer getId() {
        return id;

    public void setId(Integer id) { = id;

    public String getUsername() {
        return username;

    public void setUsername(String username) {
        this.username = username;

    public String getPassword() {
        return password;

    public void setPassword(String password) {
        this.password = password;

    public String getEmail() {
        return email;

    public void setEmail(String email) { = email;

Create a User Service

For the example we also create a simple UserService interface for JavaDoc purposes.

 * This service will handle all the user interactions
public interface UserService {

     * This method will register a user
     * @param user user that will be registered
    void register(User user);

     * Fetches a user with a given Identifier
     * @param id unique identifier of a user
     * @return User Object
    User fetchUser(Integer id);

Generate HTML JavaDoc using Maven

In order to Generate HTML JavaDoc using maven we must register the maven-javadoc plugin in the build element. This will tell maven to generate JavaDoc jar files in the install phase.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""

    <name>MAVEN - ${project.artifactId}</name>
    <description>This project will generate javadoc jar file using maven</description>




Execute maven goals

Lets build the reports using mvn clean install.

mvn clean install





You may also like...