Getting started with Nexus maven repository manager

Nexus is a maven repository manager. You can use Nexus to host your own maven repository for artifact created in your company, or for caching external artifacts.

Getting started with Nexus is pretty easy. Download the application. The package contains a webserver, so you don’t have to have a java container running. Simply unpack the downloaded archive and start the applications:

cd nexus/nexus-webapp-1.5.0/bin/jsw/linux-x86-32/
nexus start

Nexus has a web interface for managing your maven repository. The url for this web app is: http://localhost:8081/nexus/. The preconfigured admin account is admin, password: admin123.

According to the Nexus documentation you need to enable remote index downloads on a new installation, but it seems that this has been removed in the latest Nexus release. I couldn’t find the checkbox mentioned in Nexus 1.5.0.

Next you need to tell maven to use your maven repository. To do this, modify $HOME/.m2/settings.xml as follows:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <proxies></proxies>
  <servers></servers>
  <pluginGroups></pluginGroups>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

To make sure you are actually using dependencies downloaded through nexus, delete all dependencies maven has already cached on your system:

rm -rf ~/.m2/repository

To test this Nexus setup, we can create a little java application using maven. The following create a java web application:

mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=nl.iteye -DartifactId=App1
cd App1

You should now be able to compile and package your application:

mvn clean install

Next we’ll add the embedded glassfish maven plugin to our pom so we can test the web application. Add the plugin in the build section of your pom:

    <plugins>
         <plugin>
            <groupId>org.glassfish</groupId>
            <artifactId>maven-embedded-glassfish-plugin</artifactId>
            <version>3.0</version>
            <configuration>
               <app>${project.build.directory}/${build.finalName}.war</app>
               <port>7070</port>
               <containerType>web</containerType>
            </configuration>
         </plugin>
    </plugins>

When you try to run your application using the embedded glassfish plugin you’ll run into an error as maven will not be able to download all the required dependencies:

$:~/projects/jee/App1$ mvn embedded-glassfish:run
[INFO] Scanning for projects...
Downloading: http://localhost:8081/nexus/content/groups/public/org/glassfish/maven-embedded-glassfish-plugin/3.0/maven-embedded-glassfish-plugin-3.0.pom
[INFO] Unable to find resource 'org.glassfish:maven-embedded-glassfish-plugin:pom:3.0' in repository central (http://central)
Downloading: http://localhost:8081/nexus/content/groups/public/org/glassfish/maven-embedded-glassfish-plugin/3.0/maven-embedded-glassfish-plugin-3.0.pom
[INFO] Unable to find resource 'org.glassfish:maven-embedded-glassfish-plugin:pom:3.0' in repository central (http://central)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).

Project ID: org.glassfish:maven-embedded-glassfish-plugin

Reason: POM 'org.glassfish:maven-embedded-glassfish-plugin' not found in repository: Unable to download the artifact from any repository

  org.glassfish:maven-embedded-glassfish-plugin:pom:3.0

from the specified remote repositories:
  nexus (http://localhost:8081/nexus/content/groups/public)

 for project org.glassfish:maven-embedded-glassfish-plugin

To fix this problem we need to add the maven repository containing the glassfish plugin to Nexus. Log into Nexus using the admin account and, select repositories,and then add a proxy repository. Specify the following repository:

screenshot 1

Next we need to add the glassfish proxy repository to the Public Repositories group:

screenshot 2

Move the Glassfish Maven 2 Repository from available repositories to ordered group repositories:

screenshot 3

Now you should be able to start Glassfish using maven, as Nexus will be able to find the required dependencies:

$:~/projects/jee/App1$ mvn embedded-glassfish:run
[INFO] Scanning for projects...
Downloading: http://localhost:8081/nexus/content/groups/public/org/glassfish/maven-embedded-glassfish-plugin/3.0/maven-embedded-glassfish-plugin-3.0.pom
4K downloaded  (maven-embedded-glassfish-plugin-3.0.pom)
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = '7e111e395ec93ac48034fdf599552d547dc27618'; remote = '085185fbf2f1b3d0d36e557f4d42c9f47edc4d2c' - RETRYING
Downloading: http://localhost:8081/nexus/content/groups/public/org/glassfish/maven-embedded-glassfish-plugin/3.0/maven-embedded-glassfish-plugin-3.0.pom
4K downloaded  (maven-embedded-glassfish-plugin-3.0.pom)
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = '7e111e395ec93ac48034fdf599552d547dc27618'; remote = '085185fbf2f1b3d0d36e557f4d42c9f47edc4d2c' - IGNORING
Downloading: http://localhost:8081/nexus/content/groups/public/org/glassfish/maven-embedded-glassfish-plugin/3.0/maven-embedded-glassfish-plugin-3.0.jar
16K downloaded  (maven-embedded-glassfish-plugin-3.0.jar)
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = 'd6e53dbbc063ccb40aa673f0a56bafa0c2c225db'; remote = '0469be7e503a1c3df4c8ddf199b1fba3a998cca2' - RETRYING
Downloading: http://localhost:8081/nexus/content/groups/public/org/glassfish/maven-embedded-glassfish-plugin/3.0/maven-embedded-glassfish-plugin-3.0.jar
16K downloaded  (maven-embedded-glassfish-plugin-3.0.jar)
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = 'd6e53dbbc063ccb40aa673f0a56bafa0c2c225db'; remote = '0469be7e503a1c3df4c8ddf199b1fba3a998cca2' - IGNORING
[INFO] ------------------------------------------------------------------------
[INFO] Building App1 Maven Webapp
[INFO]    task-segment: [embedded-glassfish:run]
[INFO] ------------------------------------------------------------------------
Downloading: http://localhost:8081/nexus/content/groups/public/org/glassfish/extras/glassfish-embedded-all/3.0/glassfish-embedded-all-3.0.pom
10K downloaded  (glassfish-embedded-all-3.0.pom)
Downloading: http://localhost:8081/nexus/content/groups/public/org/glassfish/extras/extras/3.0/extras-3.0.pom
2K downloaded  (extras-3.0.pom)
Downloading: http://localhost:8081/nexus/content/groups/public/org/glassfish/glassfish-parent/3.0/glassfish-parent-3.0.pom
53K downloaded  (glassfish-parent-3.0.pom)
...
INFO: Security service(s) started successfully....
classLoader = WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)
SharedSecrets.getJavaNetAccess()[email protected]
Mar 9, 2010 9:34:51 PM com.sun.enterprise.web.WebApplication start
INFO: Loading application App1 at /App1
Hit ENTER to redeploy, X to exit

That’s about it.

blog comments powered by Disqus