I have setup nexus
for mirroring my maven local repository (at ~/.m2/repository.
) Since this post is still visited by a lot of people, I think it would be helpful for others if I share how I configured nexus
as a repository manager. This procedure works perfectly for me in Ubuntu 12.04
. Here it is -
1. Download nexus-2.11.1-01-bundle.tar.gz or latest version of nexus oss.
2. Extract the tar file in you home directory-
$ tar -xvf nexus-2.11.1-01-bundle.tar.gz
Now you will get two directories - nexus-2.11.1-01
and sonatype-work
in your home directory.
3. Copy these two directories to /usr/local/
directory (they can be copied to other place) -
$ cp -r nexus-2.11.1-01 /usr/local/
$ cp -r sonatype-work /usr/local/
The executable/configuration files related to nexus are stored in nexus-2.11.1-01
directory and the jar file mentioned in pom.xml
are stored in sonatype-work
directory.
These jar files are mirror of your ~/.m2/repository
. First time you issue a mvn package
command then all the jar
s are stored here. After then when you issue mvn package
again then all jars are downloaded from the nexus repository instead of downloading from the central repository.
4. Go to the /usr/local/
directory -
$ cd /usr/local/
5. Create a link to nexus-2.11.1-01
-
$ sudo ln -s nexus-2.7.0-06 nexus
6. Now to run nexus type the following in terminal -
$ bash nexus/bin/nexus console
Here nexus is attached with your console. If you close your console then the nexus server will be terminated. When you are trying to run nexus for a Ubuntu server machine then you may use screen.
Note: While trying to run nexus by using the command above there may occur 2 problems. If you do not found any problem then skip next 2 steps (step - 7 and 8)
7. First problem may occur due to insufficient permission. Read the error message and take necessary steps. But as a quick solution you may do this -
$ sudo chmod -R 777 nexus-2.11.1-01/
$ sudo chmod -R 777 sonatype-work/
8. If you are using any jdk
version lower than java 7 than the following error message may be shown -
wrapper | Launching a JVM... wrapper | JVM exited while loading the application. jvm 1 | Exception in thread "main" java.lang.UnsupportedClassVersionError: org/sonatype/nexus/bootstrap/jsw/JswLauncher : Unsupported major.minor version 51.0
In this case use jdk7 to run the command mentioned in step 6. In ubuntu its pretty easy. Assuming you have two jdk - jdk6 and jdk7. Your project runs on jdk6. Then only for running nexus you may do this from your terminal (assuming your jdk7 in /usr/lib/jvm/jdk1.7.0_45
directory) -
$ export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45
$ export PATH=$JAVA_HOME/bin:$PATH
9. Now in browser type the address - http://localhost:8081/nexus/. If step 1 to 6 (if errors occurred then step 1 to 8) are done perfectly you may successfully find the login screen. The default login user name is - admin and password is - admin123
10. Stop nexus. Just close the terminal or press Ctrl+C at step 6's terminal. In you ~/.m2
directory create an empty file named - settings.xml
. Copy the following content into this settings.xml
file -
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<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>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
11. And add these following lines in your project's pom.xml
file -
<distributionManagement>
<snapshotRepository>
<id>my-snapshots</id>
<name>My internal repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>my-releases</id>
<name>My internal repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
</distributionManagement>