Maven Tutorial
Maven in IDE
In some cases, you may need to use a private repository to host and manage your organization's Maven artifacts. This tutorial will guide you through setting up and using a private Maven repository using two popular options: Nexus Repository Manager and Artifactory.
Nexus Repository Manager
Sonatype's Nexus Repository Manager is a widely used repository management tool that can host Maven artifacts in a private repository. You can use the open-source Nexus Repository Manager OSS or the commercial Nexus Repository Manager Pro version.
Download and install Nexus Repository Manager OSS: Download the latest version of Nexus Repository Manager OSS from the Sonatype website: https://www.sonatype.com/nexus/repository-oss. Follow the installation instructions for your operating system.
Start Nexus: Start the Nexus Repository Manager using the appropriate script for your OS, usually found in the bin
folder of the installation directory.
Access Nexus: Open a web browser and navigate to http://localhost:8081. Log in with the default admin credentials (username: admin
, password: admin123
).
Create a Maven repository: In the Nexus Repository Manager interface, click on "Repositories" in the left navigation menu. Click on the "Create repository" button and choose "maven2 (hosted)" as the repository recipe. Fill in the required fields, such as "Name" and "Blob store," and click "Create repository."
Configure your project: To use your private Nexus repository, update your Maven settings.xml
file (located in your .m2
directory, e.g., ~/.m2/settings.xml
), adding the following:
<servers> <server> <id>my-nexus-repo</id> <username>admin</username> <password>admin123</password> </server> </servers> <profiles> <profile> <id>my-nexus-repo-profile</id> <repositories> <repository> <id>my-nexus-repo</id> <url>http://localhost:8081/repository/my-nexus-repo/</url> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>my-nexus-repo-profile</activeProfile> </activeProfiles>
Replace the url
value with the URL of your Nexus repository. Now, Maven will download dependencies from and upload artifacts to your private Nexus repository.
Configuring Maven for private repository usage:
settings.xml
) to include the private repository details.<!-- Example Maven settings.xml configuration --> <settings> <mirrors> <mirror> <id>private-repo</id> <url>https://your.private.repo/maven-repository</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <!-- Additional configurations... --> </settings>
Deploying and publishing artifacts to a private Maven repository:
<!-- Example deployment configuration in POM --> <distributionManagement> <repository> <id>private-repo</id> <url>https://your.private.repo/maven-repository</url> </repository> </distributionManagement>