我已经设置了 nexus
以镜像我的Maven本地仓库(位于~/.m2/repository.
),由于这篇文章仍然被很多人访问,我认为如果我分享一下我如何配置nexus
作为仓库管理器,对其他人会有所帮助。这个过程在Ubuntu 12.04
中完美地运行。以下是步骤 -
1. 下载nexus-2.11.1-01-bundle.tar.gz或最新版本的Nexus OSS。
2. 将tar文件解压到您的主目录中-
$ tar -xvf nexus-2.11.1-01-bundle.tar.gz
现在你会得到两个目录 - nexus-2.11.1-01
和 sonatype-work
,它们位于你的主目录下。
3. 将这两个目录复制到/usr/local/
目录中(它们也可以复制到其他地方) -
$ cp -r nexus-2.11.1-01 /usr/local/
$ cp -r sonatype-work /usr/local/
与nexus相关的可执行文件/配置文件存储在
nexus-2.11.1-01
目录中,
pom.xml
中提到的jar文件存储在
sonatype-work
目录中。
这些jar文件是您的
~/.m2/repository
的镜像。第一次发出
mvn package
命令时,所有
jar
都将存储在此处。然后,当您再次发出
mvn package
命令时,所有jar将从nexus存储库中下载,而不是从中央存储库中下载。
4. 转到/usr/local/
目录 -
$ cd /usr/local/
5. 创建到nexus-2.11.1-01
的链接 -
$ sudo ln -s nexus-2.7.0-06 nexus
6. 现在要运行nexus,请在终端中输入以下命令 -
$ bash nexus/bin/nexus console
这里将nexus与您的控制台连接在一起。如果您关闭控制台,则nexus服务器将被终止。当您尝试在Ubuntu服务器上运行nexus时,可以使用screen。
注意:尝试使用上述命令运行nexus时可能会出现2个问题。如果没有发现任何问题,请跳过下面的两个步骤(步骤7和8)。
7.第一个问题可能是由于权限不足而引起的。阅读错误消息并采取必要的措施。但作为快速解决方案,您可以执行以下操作 -
$ sudo chmod -R 777 nexus-2.11.1-01/
$ sudo chmod -R 777 sonatype-work/
8. 如果您使用的任何jdk
版本低于Java 7,则可能会显示以下错误消息 -
wrapper | 启动JVM... wrapper | JVM在加载应用程序时退出。 jvm 1 | "main"线程中的异常
java.lang.UnsupportedClassVersionError:
org/sonatype/nexus/bootstrap/jsw/JswLauncher:不支持的major.minor版本51.0
在这种情况下,请使用jdk7运行第6步中提到的命令。在Ubuntu上很容易做到。假设您有两个jdk-jdk6和jdk7。您的项目在jdk6上运行。然后,仅为运行nexus,您可以从终端执行此操作(假设您的jdk7位于/usr/lib/jvm/jdk1.7.0_45
目录中)-
$ export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45
$ export PATH=$JAVA_HOME/bin:$PATH
9. 现在在浏览器中输入地址 - http://localhost:8081/nexus/。如果步骤1到6(如果发生错误则为步骤1到8)都完美执行,您将成功找到登录界面。默认的登录用户名是 - admin,密码是 - admin123。
10. 停止Nexus。只需关闭终端或在第6步的终端上按Ctrl+C即可。在您的~/.m2
目录中创建一个名为-settings.xml
的空文件。将以下内容复制到此settings.xml
文件中:
<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. 接下来在你的项目的 pom.xml
文件中添加以下这些行:
<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>