Get source JARs from Maven repository
Maven Micro-Tip: Get sources and Javadocs
When you're using Maven in an IDE you often find the need for your IDE to resolve source code and Javadocs for your library dependencies. There's an easy way to accomplish that goal.
mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc
The first command will attempt to download source code for each of the dependencies in your pom file.
The second command will attempt to download the Javadocs.
Maven is at the mercy of the library packagers here. So some of them won't have source code packaged and many of them won't have Javadocs.
In case you have a lot of dependencies it might also be a good idea to use
inclusions/exclusions to get specific artifacts, the following command
will for example only download the sources for the dependency with
a specific artifactId:mvn dependency:sources -DincludeArtifactIds=guava
Source: http://tedwise.com/2010/01/27/maven-micro-tip-get-sources-and-javadocs/
Documentation: https://maven.apache.org/plugins/maven-dependency-plugin/sources-mojo.html
Get source jar files attached to Eclipse for Maven-managed dependencies
I am sure m2eclipse Maven plugin for Eclipse - the other way around - can do that. You can configure it to download both the source files and javadoc automatically for you.
This is achieved by going into Window > Preferences > Maven and checking the "Download Artifact Sources" and "Download Artifact JavaDoc"
options.
How to download sources for a jar with Maven?
2020 Update:
The maven dependency plugin should be used whit the dependency:sources
goal:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>download-sources</id>
<goals>
<goal>sources</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
This can also be run from the command line as:
mvn dependency:sources -Dsilent=true
Executing mvn dependency:sources
will force maven to download all sources of all jars in the project, if the sources are available (are uploaded in the repository where the artifact is hosted). If you want to download javadoc the command is mvn dependency:resolve -Dclassifier=javadoc
Deprecated:
It's also possible to create a profile in your settings.xml file and include the following properties:
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
How to download sources for an specific JAR dependency of a Maven project
I just found out how to do this in the plugin's documentation:
http://maven.apache.org/plugins/maven-dependency-plugin/sources-mojo.html
I solved this using the following command:
mvn dependency:sources -DincludeGroupIds=com.example.api.agents -DincludeArtifactIds=api-agent-spark
where are the source and javadoc jars for a maven repo stored in netbeans ide?
Typically in ~/.m2/repository
on *nix or C:\Documents and Settings\$USERNAME\.m2\repository
in Windows
How can I get an eclipse project to reference source jars from maven local repository in a shared project?
You don't need to do any of this.
If you use a jar as a <dependency>
in Maven, then Eclipse automatically finds the x-sources.jar
that lies next to the dependency.
So if you build a project with attached sources
jar and then use it in another Maven project, the sources
jar is found without further configuration.
Related Topics
What Is the Best Java Image Processing Library/Approach
Spring Resttemplate - How to Enable Full Debugging/Logging of Requests/Responses
Polymorphism: Why Use "List List = New Arraylist" Instead of "Arraylist List = New Arraylist"
How to Convert Outputstream to Inputstream
Using the "Final" Modifier Whenever Applicable in Java
What Is a Question Mark "" and Colon ":" Operator Used For
How to Validate Two or More Fields in Combination
What Is a Good Use Case for Static Import of Methods
Mapping Postgresql JSON Column to a Hibernate Entity Property
Creating Multiple Log Files of Different Content with Log4J
Very Confused by Java 8 Comparator Type Inference
Copy a Stream to Avoid "Stream Has Already Been Operated Upon or Closed"
Overload with Different Return Type in Java
Eclipse: How to Build an Executable Jar with External Jar
Stale Element Reference: Element Is Not Attached to the Page Document
Noclassdeffounderror: Wrong Name
Why Java Classes Do Not Inherit Annotations from Implemented Interfaces