Maven - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Maven Repository

Maven Repository

shape Introduction

Maven does a lot of things behind the scenes. Before going to the concept of repositories, one should know about the relationship between the Maven Development environment and Maven Repository. Maven Repository chapter explains about Maven archetypes and types of repositories. Maven gets the knowledge from Maven Repository, which has two types of information. The concept of dependency will be discussed in the next chapter.

Archetype

shape Description

Archetype is a model that defines the structure of project. Archetype information has different types of projects being created, folder structure and the information about projects. Maven initially generates archetype and gets all the required information about the project being done. When mvn archetype:generate command is run in the command prompt for the first time, all the plug-ins are  downloaded and gives the list of archetypes and information about the application. The inputs given to the archetype are classified into 5 types.

Archetype

Archetype is the information given to Maven about the type of project needed. Archetypes will differ based on the application to be developed. There are archetypes for J2EE applications, spring applications, hibernate applications, etc. in Maven Repository. Each archetype is a good starting point for each application.

Artifact ID

Artifact ID is used to identify the output files like jar, war or ear files.

GroupID

GroupID is an explanatory ID used to group all the artifact ID’s and gives an identification to it.

Version

Version has default snapshots, which is a piece of code to be released.

Package

Package is the location of source code. Based on the inputs provided, the java class in that archetype will be assigned to a Java class.

shape Examples

[xml] <groupId>org.splessons.itoolsinfo</groupId> <artifactId>MavenTestApp</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> [/xml]

Repository Types

shape Description

There are 3 types of repositories in Maven.
  1. Local Repository
  2. Central Repository
  3. Remote Repository
The searching sequence of dependencies in the above repository will be the same. Initially, in local repository, the next in central and then in remote repositories if given in POM file.

Local Repository

shape Description

Local repository contains the downloads of dependencies. Downloading one is enough even if there are multiple projects. Own projects can be developed in the local repository using the install command. Local repository is placed in user’s home directory by default. The location can also be changed using settings.xml. [xml] <settings> <localRepository> d:\data\java\products\maven\repository </localRepository> </settings> [/xml]

Central Repository

shape Description

By default, Maven searches for Central repository for dependencies. There is no special setup required to use the central repository.

Remote Repository

shape Description

Remote repository downloads the dependencies from a web server. It can be anywhere on the internet and even inside the local network. This repository helps in sharing the projects among the organization. To configure the remote repository in POM files, please follow the below code: [xml] <repositories> <repository> <id>splessons.code</id> <url>http://maven.splessons.com/maven2/lib</url> </repository> </repositories>[/xml]

Summary

shape Key Points

  • Maven Repository is the combination of archetypes and dependencies.
  • Archetype gives the structure of a project.
  • Local, Central and Remote are the three types of repositories.
  • Maven always checks for dependencies in the Local Repository.