zoukankan      html  css  js  c++  java
  • linux上搭建maven私服(下)

    新建maven项目之前我们先配置maven客户端中的setting.xml文件

    1、配置setting.xml文件新曾servers节点(pom.xml文件中配置的distributionManagement节点会根据id匹配此文件的server节点来获取私服用户名和密码)

     <servers>
         <server>
          <!--id不是固定值,只要保持和pom.xml中的repository id 一直就行-->
          <id>releases</id>
          <username>crelle</username>
          <password>123456</password>
        </server>
         <server>
          <id>snapshots</id>
          <username>crelle</username>
          <password>123456</password>
        </server>
      </servers>

    2、新建一个简单的maven项目

     3、配置项目中的pom.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <!--jar包的坐标-->
        <groupId>com.crelle</groupId>
        <artifactId>test</artifactId>
        <version>1.0-RELEASES</version>
        <packaging>jar</packaging>
        <!--名称和描述-->
        <name>test</name>
        <description>maven repository test</description>
        <distributionManagement>
            <!--host release配置-->
            <repository>
                <!--id和前面setting.xml中的server节点id一致-->
                <id>releases</id>
                <url>http://192.168.74.3:8081/repository/alibaba-release/</url>
            </repository>
            <!--host snapshot配置-->
            <snapshotRepository>
                <!--id和前面setting.xml中的server节点id一致-->
                <id>snapshots</id>
                <url>http://192.168.74.3:8081/repository/alibaba-snapshot/</url>
            </snapshotRepository>
        </distributionManagement>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
        </properties>
    </project>

    4、执行命令mvn deplay 部署到私服(maven会判断版本后面是否带了-SNAPSHOT,如果带了就发布到snapshots仓库,否则发布到release仓库)

     5、在项目中引用我们私服中的jar包

    让maven项目使用nexus作为远程仓库有两种方式,第一种是在项目的pom.xml中进行更改,让单个项目使用nexus仓库;另一种是通过修改maven的配置文件settings.xml进行更改,让所有项目都使用nexus仓库。我们这里采取第二种,只需配置setting.xml就可以了。还有就是拉取jar的私服仓库地址只要写一个alibaba-group就可以了,因为在创建这个组的时候,里面已经包含了其它三个仓库。

    最终的setting.xml文件:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
        <pluginGroups>
      </pluginGroups>
      <proxies>
      </proxies>
    
     <servers>
        <!--从私服拉去jar包的用户名和密码,id要和下面mirrors节点中id一致-->
        <server>
          <id>nexus-sifu</id>
          <username>crelle</username>
          <password>123456</password>
        </server>
         <server>
         <!--上传jar包到私服的用户名和密码,id要和项目中pom.xml中distributionManagement节点中的id一致-->
          <id>releases</id>
          <username>crelle</username>
          <password>123456</password>
        </server>
         <server>
          <id>snapshots</id>
          <username>crelle</username>
          <password>123456</password>
        </server>
      </servers>
    
      <mirrors>
        <mirror>
            <id>nexus-sifu</id>
            <name>internal nexus repository</name>
            <!--镜像采用配置好的组的地址-->
            <url>http://192.168.74.3:8081/repository/alibaba-group/</url>
            <mirrorOf>!internal.repo,*</mirrorOf>
        </mirror>
      </mirrors>
    
      <profiles>
        <profile>
        <!--ID用来确定该profile的唯一标识-->
           <id>jdk-1.8</id>
           <activation>
               <activeByDefault>true</activeByDefault>
               <jdk>1.8</jdk>
           </activation>
           <properties>
               <maven.compiler.source>1.8</maven.compiler.source>
               <maven.compiler.target>1.8</maven.compiler.target>
               <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
           </properties>
       </profile>
    
        <profile>
          <id>nexus-pr</id>
           <!-- 远程仓库列表 -->
          <repositories>
            <repository>
              <id>nexus-sifu</id>
              <name>Nexus Central</name>
             <!-- 虚拟的URL形式,指向镜像的URL-->
              <url>http://192.168.74.3:8081/repository/alibaba-group/</url>
              <layout>default</layout>
             <!-- 表示可以从这个仓库下载releases版本的构件-->  
              <releases>
                <enabled>true</enabled>
              </releases>
             <!-- 表示可以从这个仓库下载snapshot版本的构件 -->  
              <snapshots>
                <enabled>true</enabled>
              </snapshots>
            </repository>
          </repositories>
           <!-- 插件仓库列表 -->
          <pluginRepositories>
            <pluginRepository>
              <id>nexus-sifu</id>
              <name>Nexus Central</name>
              <url>http://192.168.74.3:8081/repository/alibaba-group/</url>
              <layout>default</layout>
              <snapshots>
                <enabled>true</enabled>
              </snapshots>
              <releases>
                 <enabled>true</enabled>
              </releases>
            </pluginRepository>
          </pluginRepositories>
       </profile>
       
      </profiles>
    
      <activeProfiles>
         <!--需要激活 <profile>中的ID才生效-->  
        <activeProfile>nexus-pr</activeProfile>
        <activeProfile>jdk-1.8</activeProfile>
      </activeProfiles>
    </settings>

    pom中引用:

      运行hello world程序:

      完毕!!!

  • 相关阅读:
    【转】算法的时间复杂度
    FFT 物理意义(转)
    【转】FIR学习1
    【转】DFT DTFT DFS FFT的关系
    【转】TCL中的数组
    【转】setup time和hold time的周期问题(slack)
    【转】TCL语法简介
    【转】亚稳态分析
    ubuntu下Samba服务器搭建
    第一次生成uImage出现的问题解决
  • 原文地址:https://www.cnblogs.com/crelle/p/13485658.html
Copyright © 2011-2022 走看看