ITPub博客

首页 > 应用开发 > Java > 搭建Maven和Nexus环境

搭建Maven和Nexus环境

原创 Java 作者:壹頁書 时间:2016-01-07 18:03:03 0 删除 编辑
下载Maven和Nexus
apache-maven-3.3.9
nexus-2.12.0-01

解压nexus,进入目录
D:\nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin>
安装服务
D:\nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin>nexus.bat install
启动服务
D:\nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin>nexus.bat start
wrapper  | Starting the nexus service...
wrapper  | Waiting to start...
wrapper  | Waiting to start...
wrapper  | Waiting to start...
wrapper  | Waiting to start...
wrapper  | Waiting to start...
wrapper  | nexus started.

访问如下地址测试Nexus私服是否安装成功
http://127.0.0.1:8081/nexus

管理员的默认密码是
admin/admin123

同步Maven中央库的索引文件


修改配置,下载远程的索引


然后Repair索引.


可以看到正在执行的RepairIndex的任务.



在项目的pom.xml文件中,配置私服地址

  1.     <repositories>
  2.         <repository>
  3.             <id>nexus</id>
  4.             <name>Team Nexus Repository</name>
  5.             <url>http://localhost:8081/nexus/content/groups/public</url>
  6.         </repository>
  7.     </repositories>
  8.     <pluginRepositories>
  9.         <pluginRepository>
  10.             <id>nexus</id>
  11.             <name>Team Nexus Repository</name>
  12.             <url>http://localhost:8081/nexus/content/groups/public</url>
  13.         </pluginRepository>
  14.     </pluginRepositories>

或者拷贝maven/conf/settings.xml文件到用户家目录的.m2文件夹下
修改该文件
  1.     <mirrors>
  2.             <mirror>
  3.                 <id>central</id>
  4.                 <mirrorOf>*</mirrorOf> <!-- * 表示让所有仓库使用该镜像-->
  5.                 <name>central-mirror</name>
  6.                 <url>http://localhost:8081/nexus/content/groups/public/</url>
  7.             </mirror>
  8.     </mirrors>

如果需要从本地发布jar包到私服
需要先在私服上创建一个账号


设置用户,注意权限


然后在项目的pom中加入如下配置

  1.     <distributionManagement>
  2.         <repository>
  3.             <id>deployment</id>
  4.             <name>Nexus Release Repository</name>
  5.             <url>http://127.0.0.1:8081/nexus/content/repositories/releases</url>
  6.         </repository>
  7.         <snapshotRepository>
  8.             <id>deployment</id>
  9.             <name>Nexus Snapshot Repository</name>
  10.             <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>
  11.         </snapshotRepository>
  12.     </distributionManagement>

然后修改家目录.m2文件下的settings.xml文件
  1. <servers>
  2.         <server>
  3.             <id>deployment</id>
  4.             <username>dev</username>
  5.             <password>123456</password>
  6.         </server>        
  7. </servers>

标红的ID需要一致.

这时候运行如下命令
E:\workspace\test>mvn clean deploy
就可以将jar包直接发布在私服了.

参考:
http://tianweili.github.io/blog/2015/03/17/linux-nexus-maven-private-server/


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29254281/viewspace-1973387/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-10-19

  • 博文量
    620
  • 访问量
    6339892