How to download from Maven remote repository?

According to Apache Maven :

Downloading in Maven is triggered by a project declaring a dependency that is not present in the local repository (or for a SNAPSHOT, when the remote repository contains one that is newer). By default, Maven will download from the central repository.

In Maven, when you’re declared library does not exist either inlocal repository nor Maven center repository, the process will stop and output error messages to your Maven console.

1. Example

The org.jvnet.localizer is only available at Java.net repository.

pom.xml

    <dependency>
        <groupId>org.jvnet.localizer</groupId>
        <artifactId>localizer</artifactId>
        <version>1.8</version>
    </dependency>

When you build this Maven project, it will fail and output dependency not found error message.

Updated 12/12/2012
The org.jvnet.localizer is now available in Maven center repository.

2. Declare Java.net repository

To tell Maven to get the dependency from Java.net, you need to declared a remote repository in your pom.xml file like this :

pom.xml

    <repositories>
	<repository>
	    <id>java.net</id>
	    <url>https://maven.java.net/content/repositories/public/</url>
	</repository>
    </repositories>

Now, Maven’s dependency library look-up sequences is changed to :

  1. Search in Maven local repository, if not found, go step 2, else exit.
  2. Search in Maven central repository, if not found, go step 3, else exit.
  3. Search in java.net Maven remote repository, if not found, prompt error message, else exit.

References

  1. How To Add Remote Repository In Maven

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
7 Comment threads
4 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
9 Comment authors
Jason RembertQuoc AnhRoarLionsnipermkyong Recent comment authors
newest oldest most voted
Jason Rembert
Guest
Jason Rembert

You can also download the jar files with dependencies from this site: http://jar-download.com/

Quoc Anh
Guest
Quoc Anh

i’m start learning about maven, and your blog is very helpful. thank you verymuch.

gilbert
Guest
gilbert

Your blog is very helpful for beginners in maven. I wanted to know, how do I find out the of a repository when I already have the dependency information. for example, the dependency information is:

org.eclipse.equinox
org.eclipse.osgi
3.4.2

how do I find out the repository information from the element

Amit
Guest
Amit

In the post you have mentioned “…a dependency that is not present in the local repository (or for a SNAPSHOT, when the remote repository contains one that is newer)… “. I don’t know what you mean by the term “SNAPSHOT”. Can you please explain it a bit or direct me to the link where it is explained.

Thanks.

sniper
Guest
sniper

?????????snapshot??????????

RoarLion
Guest
RoarLion

A snapshot version in Maven is one that has not been released. The idea is that before a 1.0 release (or any other release) is done, there exists a 1.0-SNAPSHOT. That version is what might become 1.0. It’s basically “1.0 under development”. This might be close to a real 1.0 release, or pretty far (right after the 0.9 release, for example). The difference between a “real” version and a snapshot version is that snapshots might get updates. That means that downloading 1.0-SNAPSHOT today might give a different file than downloading it yesterday or tomorrow. Usually, snapshot dependencies should only exist… Read more »

Siddhanta Kumar Pattnaik
Guest
Siddhanta Kumar Pattnaik

Greate mkyong…
Very Very thanks to u for ur Tutorial……………

venkat
Guest
venkat

hello mkyong,

I learnt a few java technologies before. now am learning new technologies from yours.
since am a novice to real tome development, am just curious to know how the project phases go on from specification to testing.
could you post an article or ideas accordingly. Thank you

RoarLion
Guest
RoarLion

it depends on the process.
usual water fall way .

requirement Specification -> Architechture-> ->functional specifications -> design -> implmentation (development ) -> unit testing -> QA testing -> system integration testing -> UAT deployment -> UAT testing (user acceptance testing ) -> production deployment -> post production support

correct me If I am wrong

trackback
Maven Tutorials | Tutorials

[…] Maven remote repository – link1, link2 Not all libraries are store in Maven central repository, often times, you need to add some remote repositories to download the libraries from another location instead of the default central repository. […]