阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Nexus配置实践

104次阅读
没有评论

共计 5958 个字符,预计需要花费 15 分钟才能阅读完成。

Nexus 的安装以及怎样配置 proxy 就不讲解了,网上随便搜索就是一堆。我所在搜狐武汉研发这边暂时还没有 Nexus 可用,所以抽了时间我就搭建了一个。安装和搭建及其简单,但是如何配置到项目呢,尤其是有多种配置方式。

Maven 3.1.0 发布,项目构建工具 http://www.linuxidc.com/Linux/2013-07/87403.htm

Linux 安装 Maven http://www.linuxidc.com/Linux/2013-05/84489.htm

Maven3.0 配置和简单使用 http://www.linuxidc.com/Linux/2013-04/82939.htm

Ubuntu 下搭建 sun-jdk 和 Maven2 http://www.linuxidc.com/Linux/2012-12/76531.htm

Maven 使用入门 http://www.linuxidc.com/Linux/2012-11/74354.htm

1. 想要让 maven 项目能够从 Nexus 中取 jar,其实只需要在 POM 中配置如下一段即可:

  <repositories> 
        <repository> 
            <snapshots> 
                <enabled>true</enabled> 
            </snapshots> 
            <id>public</id> 
          <name>Public Repositories</name> 
            <url>http://127.0.0.1:8081/nexus/content/groups/public/</url> 
        </repository> 
    </repositories> 
    <pluginRepositories> 
        <pluginRepository> 
            <id>public</id> 
            <name>Public Repositories</name> 
            <url>http://127.0.0.1:8081/nexus/content/groups/public/</url> 
        </pluginRepository> 
    </pluginRepositories>

2. 按照上述方式其实可以简单使用 Nexus 了,但是难道每个项目都需要这样配置一下,很麻烦,所以下面有另外一种办法,修改全局 settings.xml 文件,在文件里面增加如下代码:

  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>false</enabled></snapshots>
        </repository>
      </repositories>
    <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>false</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>nexus</activeProfile>
    <activeProfile>public-snapshots</activeProfile>
  </activeProfiles>

这样配置完成后,就可以在任何 maven 项目中使用咱们的 Nexus 了。

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-06/103054p2.htm

但是这只是指能够从 Nexus 上下载 Jar,如果我们希望自己的项目能够自动 deploy 到 Nexus 上去呢,就需要在 settings.xml 中再增加如下代码:

<!– 设置 server 的账号密码,使之可以 deploy –>
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>

<mirrors>
<mirror>
<!–This sends everything else to /public –>
<id>releases</id>
<mirrorOf>central</mirrorOf>
<url>http://127.0.0.1:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
<!–This is used to direct the public snapshots repo in the
profile below over to a different nexus group –>
<id>snapshots</id>
<mirrorOf>public-snapshots</mirrorOf>
<url>http://127.0.0.1:8081/nexus/content/groups/public-snapshots</url>
</mirror>
</mirrors>

同时需要在项目的 POM 文件里增加:

<!– deploy path –>
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal snapshots</name>
<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

好了,这样就完成了 Nexus 使用配置了。

Maven 的详细介绍 :请点这里
Maven 的下载地址 :请点这里

Nexus 的安装以及怎样配置 proxy 就不讲解了,网上随便搜索就是一堆。我所在搜狐武汉研发这边暂时还没有 Nexus 可用,所以抽了时间我就搭建了一个。安装和搭建及其简单,但是如何配置到项目呢,尤其是有多种配置方式。

Maven 3.1.0 发布,项目构建工具 http://www.linuxidc.com/Linux/2013-07/87403.htm

Linux 安装 Maven http://www.linuxidc.com/Linux/2013-05/84489.htm

Maven3.0 配置和简单使用 http://www.linuxidc.com/Linux/2013-04/82939.htm

Ubuntu 下搭建 sun-jdk 和 Maven2 http://www.linuxidc.com/Linux/2012-12/76531.htm

Maven 使用入门 http://www.linuxidc.com/Linux/2012-11/74354.htm

1. 想要让 maven 项目能够从 Nexus 中取 jar,其实只需要在 POM 中配置如下一段即可:

  <repositories> 
        <repository> 
            <snapshots> 
                <enabled>true</enabled> 
            </snapshots> 
            <id>public</id> 
          <name>Public Repositories</name> 
            <url>http://127.0.0.1:8081/nexus/content/groups/public/</url> 
        </repository> 
    </repositories> 
    <pluginRepositories> 
        <pluginRepository> 
            <id>public</id> 
            <name>Public Repositories</name> 
            <url>http://127.0.0.1:8081/nexus/content/groups/public/</url> 
        </pluginRepository> 
    </pluginRepositories>

2. 按照上述方式其实可以简单使用 Nexus 了,但是难道每个项目都需要这样配置一下,很麻烦,所以下面有另外一种办法,修改全局 settings.xml 文件,在文件里面增加如下代码:

  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>false</enabled></snapshots>
        </repository>
      </repositories>
    <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>false</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>nexus</activeProfile>
    <activeProfile>public-snapshots</activeProfile>
  </activeProfiles>

这样配置完成后,就可以在任何 maven 项目中使用咱们的 Nexus 了。

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-06/103054p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计5958字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中