使用nexus创建私服

来源:action inmaven3的第九章

在window下使用nexus创建私服

1、 下载

可以从http://nexus.sonatype.org/download/下载最新版本的Nexus,如:nexus-webapp-1.7.2-bundle.zip或者nexus-webapp-1.7.2.war。

2、 安装

1) Bundle方式

Nexus的Bundle自带了Jetty容器,因此用户不需要额外的web容器就能直接启动Nexus,解压后,直接运行nexus-webapp-1.7.2/bin/jsw/windows-x86-32/nexus.bat

安装和配置好后,下载的jar包默认位置是sonatype-work/nexus/storage目录下

2) WAR方式

War包支持主流的Web容易,如Tomcat、Glassfish、Jetty和Resin。

直接将Nexus的War包复制到Tomcat的webapps下,启动Tomcat就OK了

3、 配置Nexus的代理仓库

在配置Maven Central的Remote Storage Location为:http://mirrors.ibiblio.org/pub/mirrors/maven2/,Download Remote Indexes为true

创建Sonatype Repository,设置Remote Storage Location为:http://repository.sonatype.org/content/groups/public/,Download Remote Indexes为true

在Public Repositories下,将Available Repositories的仓库添加到左边的Ordered Group Repositories,注意将常用的仓库放到前面。


4、 如果需要还可以在POM文件中添加远程仓库的配置

<repositories>

              <!-- JBoss Repository used for Java EE 6 pieces -->

              <repository>

                     <id>repository.jboss.org</id>

                     <name>JBoss Repository</name>

                     <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>

              </repository>

 

              <repository>

                     <id>org.springframework.maven.milestone</id>

                     <name>Spring Maven Milestone Repository</name>

                     <url>http://maven.springframework.org/milestone</url>

                     <snapshots>

                            <enabled>false</enabled>

                     </snapshots>

              </repository>

       </repositories>

 

 在POM文件配置nexus仓库,这样只响应该项目

<project>  
...  
<distributionManagement>  
  <repository>  
    <id>nexus-releases</id>  
      <name>Nexus Release Repository</name>  
      <url>http://<Your Nexus IP>/nexus/content/repositories/releases/</url>  
  </repository>  
  <snapshotRepository>  
    <id>nexus-snapshots</id>  
    <name>Nexus Snapshot Repository</name>  
    <url>http://<Your Nexus IP>/nexus/content/repositories/snapshots/</url>  
  </snapshotRepository>  
</distributionManagement>  
...  
</project>  
在settings.xml配置nexus仓库,这样就响应整台机子的项目

<profiles>  
        <profile>  
            <id>nexus</id>  
            <repositories>  
                <repository>  
                    <id>nexus</id>  
                    <name>local private nexus</name>  
                    <url><Your Nexus IP>/nexus/content/groups/public</url>  
                    <releases>  
                        <enabled>true</enabled>  
                    </releases>  
                    <snapshots>  
                        <enabled>false</enabled>  
                    </snapshots>  
                </repository>  
                <repository>  
                    <id>nexus</id>  
                    <name>local private nexus</name>  
                    <url>http://<Your Nexus IP>/nexus/content/groups/public-snapshots</url>  
                    <releases>  
                        <enabled>false</enabled>  
                    </releases>  
                    <snapshots>  
                        <enabled>true</enabled>  
                    </snapshots>  
                </repository>  
  
            </repositories>  
            <pluginRepositories>  
                <pluginRepository>  
                    <id>nexus</id>  
                    <name>local private nexus</name>  
                    <url>http://<Your Nexus IP>/nexus/content/groups/public</url>  
                    <releases>  
                        <enabled>true</enabled>  
                    </releases>  
                    <snapshots>  
                        <enabled>false</enabled>  
                    </snapshots>  
                </pluginRepository>  
                <pluginRepository>  
                    <id>nexus</id>  
                    <name>local private nexus</name>  
                    <url>http://<Your Nexus IP>/nexus/content/groups/public-snapshots</url>  
                    <releases>  
                        <enabled>false</enabled>  
                    </releases>  
                    <snapshots>  
                        <enabled>true</enabled>  
                    </snapshots>  
                </pluginRepository>  
            </pluginRepositories>  
        </profile>  
    </profiles>  
...  
    <activeProfiles>  
        <activeProfile>nexus</activeProfile>  
    </activeProfiles> 
配置镜像让nexus只使用私服,在settings.xml中

<mirrors>
    <mirror>
      <!--This is used to direct the public snapshots repo in the
          profile below over to a different nexus group -->
      <id>nexus-public-snapshots</id>
      <mirrorOf>public-snapshots</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
    </mirror>
    <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>development</id>
      <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>
    <profile>
      <!--this profile will allow snapshots to be searched when activated-->
      <id>public-snapshots</id>
      <repositories>
        <repository>
          <id>public-snapshots</id>
          <url>http://public-snapshots</url>
          <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>public-snapshots</id>
          <url>http://public-snapshots</url>
          <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>development</activeProfile>
  </activeProfiles>


注意:

repository的id可以随便取,只要有意义就OK,但是如果与其他地方发id一样,就会覆盖掉其他的,中央仓库默认是central,就是说当取id为central就把中央仓库覆盖,

还有要注意server的id、mirror的id和repository的id的意义与差别





  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值