maven学习笔记三

1、nexus简介

    这个工具的主要作用就是搭建maven仓库的私服用的,也就是以后在maven项目中用到的jar包不首先去中央仓库中寻找,而是先去这个nexus仓库中寻找,找不到的时候,这个仓库会自动关联中央仓库下载所需要的jar包。

如何下载:

可以直接在搜索引擎中搜索“nexus sonatype”,进行下载。

2、安装配置nexus

第一步、下载好“nexus-2.11.2-06”,将其解压到安装目录。

第二步、将“NEXUS_HOME”配置到环境变量中。可以在cmd命令中输入nexus命令进行检验。出现以下画面表示配置成功:


在以上的画面中,start表示开启nexus服务,stop表示结束nexus服务,restart表示重启nexus服务,installl表示安装nexus服务,uninstall表示卸载nexus服务。

第三步、(如果电脑上装有jdk就不必配置了)修改配置文件中java命令的位置,我们在安装目录中找到“E:\Applications\nexus\nexus-2.11.2-06\bin\jsw\conf\ wrapper.conf”这个文件,里面有这段代码:

# Set the JVM executable
# (modify this to absolute path if you needa Java that is not on the OS path)
wrapper.java.command=java

将其指定为java命令的位置为:

# Set the JVM executable
# (modify this to absolute path if you needa Java that is not on the OS path)
wrapper.java.command=java

第四步、从第二步中我们知道,下一步就是要安装和启动nexus服务。在命令行中输入:

nexus install就可以安装nexus服务了,安装完成后可以用nexusstart来启动nexus服务。

第五步、启动服务后,我们可以在浏览器中通过“http://localhost:8081/nexus”来访问nexus的仓库了。进入之后我们可以用超级管理员的身份去登入:账号:admin,秘密:admin123。

3、nexus工厂简介

工厂截图为:


hosted类:

    是为本地服务的,比如本地上传本地包到工厂等操作。

proxy类:

    是各种工厂的代理类,如果本地种找不到包,则会通过proxy去寻找。

group类:

    集合类,为了在maven项目中配置方面所使用的。

4、配置当前项目的中央工厂为nexus

    只需要在当前项目的pom.xml文件中加入:

<respositories>
         <respository>
                  <id>nexus</id>
                  <name>nexusrespository</name>
                  <url>http://localhost:8081/nexus/content/groups/public/ </url>
         </respository >
</ respositories>

    这样,当前项目在寻找包的时候会首先去nexus去寻找,如果寻找不到则会最终的中央工厂中寻找。

5、配置所有项目的中央工厂为nexus

配置这种全局属性,肯定是在maven的setting.xml配置文件中配置,我们需要在profile节点中加入以下配置项:

<profile>
     <id>nexusProfile</id>
     <respositories>
         <respository>
                  <id>nexus</id>
                  <name>nexusrespository</name>
                  <url>http://localhost:8081/nexus/content/groups/public/ </url>
         </respository >
                  <releases>
                          <enabled>true</enabled>
                  </releases>
                  <!--snapshots默认是关闭的,我们这里需要将它手动启动 -->
                  <snapshots>
                          <enabled>true</enabled>
                  </snapshots>
     </respositories>
</profile>

之后激活它:

 <activeProfiles>
   <activeProfile>nexusProfile</activeProfile>
 </activeProfiles>

这样以后所有的项目都会从nexus工厂中下载包了。

6、配置项目只从nexus工厂中找,而不去真正的中央工厂

    这里需要配置mirror镜像,这一项配置好之后,上面的“5”就没有存在的必要了,配置文件如下:

    <!-- 工厂镜像,只要morrorOf中的工厂要访问,都会自动来找镜像,如果镜像无法访问就不会再去中央工厂 -->
    <mirror>
     <id>nexusMirror</id>
      <mirrorOf>*</mirrorOf>
     <name>Human Readable Name for this Mirror.</name>
     <url>http://localhost:8081/nexus/content/groups/public/</url>
   </mirror>

7、将自己的项目发布到nexus

    想要将自己的项目发布到nexus是需要用户权限的,在自己的maven的pom.xml设置如下:

<distributionManagement>
         <repository>
                  <id>user-release</id>
                  <name>userrelease resp</name>
                  <url>http://localhost:8081/nexus/content/repositories/releases/ </url>
         </repository >
         <snapshotRespository>
                  <id>user-snapshots</id>
                  <name>usersnapshots resp</name>
                  <url>http://localhost:8081/nexus/content/repositories/snapshots/ </url>
         </snapshotRespository >
</ distributionManagement >

    之后再setting.xml设置如下:

<distributionManagement>
         <repository>
                  <id>user-release</id>
                  <name>userrelease resp</name>
                  <url>http://localhost:8081/nexus/content/repositories/releases/ </url>
         </repository >
         <snapshotRespository>
                  <id>user-snapshots</id>
                  <name>usersnapshots resp</name>
                  <url>http://localhost:8081/nexus/content/repositories/snapshots/ </url>
         </snapshotRespository >
</ distributionManagement >

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值