Maven attach source code for external Jar

For Java project that uses Maven for dependency and building we can attach the third party library source. By default the source is not available, using the following commands we can down load the associated source and java doc from maven repository by reading the project pom file.

Maven will not be able to download sources and docs if those were not published for a particular library.


mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc
//to download source for only one library
mvn dependency:sources -DincludeArtifactIds=spring-boot


Now after executing the above two commands, maven will download the respective sources and java docs. Now we can attach the source in the IDE. For eclipse specially it is better to use the Maven Eclipse plugin

mvn eclipse:eclipse -DdownloadSources=true
mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=false

Executing the above commands will also download the sources and it also updates the .classpath file. Now refreshing the Project in side eclipse should be able to map the corresponding sources for the external jars.

Comments

Popular posts from this blog

Converting Java Map to String

Difference between volatile and synchronized

Invoking EJB deployed on a remote machine