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.
BTW, you can ommit default groupId for plugins: org.apache.maven.plugins
Thank you. Had been looking for this :) Works like a charm.
Hi,
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
..
src/main/java
src/main/resources
…
Regards,
Zaid
Hi,
Zaid – could you explain a bit more what and where in pom.xml file should I put to pack sources in original jar?
To build a single .jar with sources do not use the maven-source-plugin. Use the following entry in the pom.xml:
${basedir}/src/main/resources
${basedir}/src/main/java
(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
Angelo
Ah, I see, the tags vanish here.
I posted the code here:
http://pastebin.com/f3164f918
Hope it helps.
Angelo
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).
Thanks,
Jitesh
Jitesh: Please try a “mvn eclipse:clean eclipse:eclipse” to generate new .classpath files (they reference the source packages). Then refresh your Eclipse project.
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.