Using the Maven Source Plugin

When using an ordinary jar library, IDEs like Eclipse's JDE don't have enough information to display inline javadocs for referenced classes. You have to manually direct Eclipse to the library's source code to take advantage of inline documentation. Maven's source plugin provides a convenient solution to this problem. When building the library, the plugin creates a source jar containing the package's source code. This source package can be installed or deployed into your repository. Maven's eclipse plugin then adds the source package to the generated .classpath file.

This is how it works. Before installing or deploying your library, run the source plugin:

mvn source:jar

Your next install or deploy call will take care of the rest. In the dependent project (the one using your library), run the eclipse plugin:

mvn eclipse:eclipse

After refreshing the project in eclipse, you should now have access to inline documentation.

If you don't want to run source:jar each time, you can attach the call to the build lifecycle's package phase:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-source-plugin</artifactId>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

After running mvn package, there should be a source package in your target directory.

social