1、解压后启动服务
执行 E:\Program\nexus\nexus-2.9.1-02\bin\jsw\windows-x86-32 下的 console-nexus.bat
2、Nexus启动报错: Unsupported major.minor version 51.0
原因是jdk版本不匹配,nexus从2.6版本开始就不支持jdk1.6了,换成1.7就可以了
修改 E:\Program\nexus\nexus-2.9.1-02\bin\jsw\conf 下的 wrapper.conf
wrapper.java.command=E:\Program\Java\jdk1.7.0\bin\java
3、启动成功后访问地址
http://localhost:8081/nexus/
4、maven nexus本地库配置
<mirror> <id>nexus-public</id> <mirrorOf>public</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://127.0.0.1:8081/nexus/content/groups/public</url> </mirror> <profile> <id>nexus</id> <repositories> <repository> <id>nexus</id> <name>local private nexus</name> <url>http://127.0.0.1:8081/nexus/content/groups/public</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>local private nexus</name> <url>http://127.0.0.1:8081/nexus/content/groups/public</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>
5、分发构件至远程仓库
mvn install 会将项目生成的构件安装到本地Maven仓库,mvn deploy 用来将项目生成的构件分发到远程Maven仓库。本地Maven仓库的构件只能供当前用户使用,在分发到远程Maven仓库之后,所有能访问该仓库的用户都能使用你的构件。
我们需要配置POM的distributionManagement来指定Maven分发构件的位置,如下:
<project> <distributionManagement> <repository> <id>user-release</id> <name>Nexus Release Repository</name> <url>http://127.0.0.1:8081/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>user-snapshot</id> <name>Nexus Snapshot Repository</name> <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement> </project>
Maven区别对待release版本的构件和snapshot版本的构件,snapshot为开发过程中的版本,实时,但不稳定,release版本则比较稳定。Maven会根据你项目的版本来判断将构件分发到哪个仓库。
一般来说,分发构件到远程仓库需要认证,如果你没有配置任何认证信息,你往往会得到401错误。这个时候,如下在settings.xml中配置认证信息:
<server> <id>user-release</id> <username>deployment</username> <password>deployment123</password> </server> <server> <id>user-snapshot</id> <username>deployment</username> <password>deployment123</password> </server>
需要注意的是,settings.xml中server元素下id的值必须与POM中repository或snapshotRepository下id的值完全一致。将认证信息放到settings下而非POM中,是因为POM往往是它人可见的,而settings.xml是本地的。
配置完成后 执行 mvn deploy,显示build success表明成功,然后访问nexus,搜索看能不能找到刚才发布的包。找到了就ok了。
6、nexus启动失败:The nexus service was launched, but failed to start
可能是端口占用造成的,nexus默认端口是8081,如果被占用则启动失败
解决办法:修改 C:\Program\nexus-2.9.1-02\conf\nexus.properties application-port=8086
7、nexus默认用户名密码 admin/admin123 ,有些功能,比如上传jar包,需要登录后才能看到