Maven Repository
Source JARs
Java
Coding
Software Development

Download source JARs (sources.jar) from a Maven repository

Codemia Knowledge Hub ·

Run mvn dependency:sources to download the source JARs for all of your project's dependencies into the local repository. For a single library, download its -sources.jar file from the repository's web interface, or let your IDE fetch sources automatically.

What a source JAR contains

A source JAR mirrors a normal binary JAR but contains the .java source files that correspond to its class files. Keeping source and binaries in separate JARs keeps production artifacts lean while letting developers download the source when they need it.

Source JARs let you step through library code while debugging, learn from well-designed code, and read the comments and annotations that often serve as the best documentation.

Option 1: the Maven Dependency Plugin

The Maven Dependency Plugin's dependency:sources goal downloads the source code of all your project dependencies:

bash
mvn dependency:sources

Maven fetches the source JARs for every dependency listed in your pom.xml and stores them in your local repository, which is especially useful for large projects with many dependencies, since one command covers all of them.

Option 2: manual download from the repository website

Repositories such as Maven Central or JFrog have web interfaces. Open the artifact's page and download the file labeled -sources.jar. This is straightforward and works for a one-off lookup, but it becomes impractical when you need sources for many dependencies.

Option 3: let the IDE download sources

IntelliJ IDEA and Eclipse can download source JARs automatically, usually configured in the IDE's Maven settings, which suits everyday development. In IntelliJ, go to File > Settings > Build, Execution, Deployment > Build Tools > Maven > Downloading and enable "Download sources automatically."

Practical tips

  • Download only what you need to keep storage use down.
  • Check licenses to make sure your use of the source code complies.
  • Use trusted, official repositories to avoid malicious code.

The three approaches compare like this:

MethodEase of UseIdeal Usage Scenario
Maven Dependency PluginHighMultiple dependencies; batch updates
Manual DownloadMediumSingle, isolated cases
Integrated Development EnvironmentHighContinuous everyday development

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms