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:


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

This entry was posted in java and tagged , , . Bookmark the permalink.

9 Responses to Using the Maven Source Plugin

  1. Oleksandr says:

    BTW, you can ommit default groupId for plugins: org.apache.maven.plugins

  2. Santhosh says:

    Thank you. Had been looking for this :) Works like a charm.

  3. Zaid Fattuhi says:


    This will generate sources in separate jar. If somebody wantsto attach the source code with the original jar (not in a separate jar with -source classifier) then add the following to pom.xml





  4. Michal Chmielarz says:


    Zaid – could you explain a bit more what and where in pom.xml file should I put to pack sources in original jar?

  5. Angelo Neuschitzer says:

    To build a single .jar with sources do not use the maven-source-plugin. Use the following entry in the pom.xml:



    (If you want to use that for gwt / gxt you also have to construct a .gwt.xml in your src/main/resources… that you have to include in the target .gwt.xml)

    Good Luck


  6. Angelo Neuschitzer says:

    Ah, I see, the tags vanish here.
    I posted the code here:

    Hope it helps.


  7. Jitesh says:

    Hi Angelo,

    So I went with the approach that you mentioned, what is happening is, the source is getting attached but then I dont see the package in the eclipse package explorer(of the project that is using the library).


  8. mafr says:

    Jitesh: Please try a “mvn eclipse:clean eclipse:eclipse” to generate new .classpath files (they reference the source packages). Then refresh your Eclipse project.

  9. Mukesh Harshwal says:

    I want to develop a maven plugin having two goals.Please help be for this and if possible then send me sample code.
    Thanks in advance.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s