I am using Maven in my projects from last couple of years, and the automatically downloading the Jars from repository feature of maven is really helpful for developers. But If you are using Eclipse and want to read/analyse Source Code or Java Doc of API then you need the jar file that contains the Source code and java doc of the API, but unfortunately maven does not download and attach the source code and java doc of the APIs automatically.
Maven provides some different ways to download and attach that source code and Java Doc:
- Using maven eclipse plugin
- Using maven dependency plugin
Note: The sources and javadocs of the libraries must exist in the repository so that the plugin can download it and attach it.
1. Maven eclipse plugin:
Maven dependencies that are deployed with the source and javadocs can be downloaded and attached to the Eclipse library by using maven-eclipse-plugin. It can be done by:
- passing command-line argument to the maven-eclipse-plugin, or
- by declaring in the pom.xml
1.1 passing command-line argument to maven-eclipse-plugin:
This example shows that how to do this by passing command line argument to the maven-eclipse-plugin:
mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
1.2 declaring in the pom.xml
This sample pom shows that how to declare downloadSources and downloadJavadocs configuration in pom.xml
2. Maven dependency plugin:
maven-dependency-plugin provides a goal named sources that resolves the project source dependencies from the repository.
This is useful when you want the source attachments downloaded to your local repository and you don’t want to use the eclipse plugin to do this since the eclipse plugin creates/overwrites the eclipse files.
really good post…
I just want to tell you that I am newbie to blogging and site-building and seriously loved your web page. Likely I’m likely to bookmark your blog post . You really have exceptional well written articles. Bless you for sharing your website.
good idea im gonna try it
Very nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed browsing your blog posts. After all Iâ€™ll be subscribing to your feed and I hope you write again very soon!
i love your blog, i have it in my rss reader and always like new things coming up from it.
Thnx, I’ll try my best to provide some more useful articles ….
Thanks for the post, I was loooking for exactly same requirement to download source and attach during mvn run.
Thanks very nice