精简nexus私服搭建

  maven对项目源码和依赖管理的好处不言而喻,不过所依赖仓库都是外网那些常用提供的仓库地址,基于安全,当外网环境有限制,或私有共通jar需共享时,则会需要搭建内部私服,以下说明基于Linux环境。

  1. maven 安装   安装很简单,主要就几个步骤和设置。

  a.  wget 安装包下载地址;   b.  tar zxvf 压缩的安装包 (如果需要安装到指定位置将包移动 : mv  源路径  目的地址; );  

  c. 配置环境变量   编辑 vi /etc/profile  且增加  export MAVEN_HOME=解压路径 与 export PATH=$PATH:$MAVEN_HOME/bin  d. 配置生效  source /etc/profile   e.验证 mvn -v。

  2. 安装nexus  (据说不提倡用 nexus3.x 以上版本,用nexus2.x版本 , JDK版本1.7以上)

  a. 下载nexus2.x 安装包 b. 解压  tar  zxvf   安装包;   c.  如改端口在  /conf/nexus.properties  d.  启动运行 切到  cd nexus-2.x/bin  再执行  ./nexus  start

  e. 访问  http://xxx.xxx.xxx.xx:8081/nexus/   默认 admin/admin123  (如果启动要root权限 用 sudo sh nexus  start启动 )

  3. 私服仓库使用及管理 

  a. 登录进去,nexus默认会有已创建的常用仓库分类,含 snapshots:开发过程中的版本仓库  release:正式发布的版本仓库  public:maven主库  3rd party,存第三方的jar

  b. maven setting.xml设置  (注意 两个xml  对应 id保持一致 )

  <servers>

<server>
    <id>releases</id>
        <username>admin</username>
    <password>admin123</password>
</server>
<server>
     <id>snapshots</id>
        <username>admin</username>
     <password>admin123</password>    
</server>       
                       
<server>
        <id>public</id>
        <username>admin</username>
        <password>admin123</password>
</server>
</servers>

  c. maven pom.xml设置 

   <groupId> News_Recommend</groupId>
   <artifactId> News_Recommend</artifactId>
   <version> 0.0.1-SNAPSHOT</version>
   <packaging> jar</packaging>

<!-- 设定主仓库 -->
<repositories>
<!-- nexus私服 -->
<repository>
<id> public</id>
<url> http://xxxx:8081/nexus/content/groups/public/ </url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
 
<!-- 自动打包 -->
    <distributionManagement>
        <repository>
            <id>releases</id>
            < url> http://xxxx:8081/nexus/content/repositories/releases </url >
        </repository>
        <snapshotRepository>
            <id>snapshots </id>
            <url> http://xxxx:8081/nexus/content/repositories/snapshots </url >
        </snapshotRepository >
    </distributionManagement >

  d. 打成jar上传私服  工程右键-->run as-->run configuration   进入 nexus后台可看到上传的jar , 如要release版本  <version> 0.0.1-SNAPSHOT</version> 改   <version> 0.0.1</version>

  

  参考 http://www.cnblogs.com/zhongshengzhen/p/nexus_maven.html

 

猜你喜欢

转载自www.cnblogs.com/ymxsnsp/p/10052928.html
今日推荐