zoukankan      html  css  js  c++  java
  • maven私服搭建

    maven私服搭建

    搭建私服的工具选择

    Apache基金会的archiva

    http://archiva.apache.org/

    JFrog的Artifactory

    https://jfrog.com/artifactory/

    Sonatype的Nexus

    https://my.sonatype.com/
    这些都是开源的私服软件,都可以自由使用。用的最多的是第三种Nexus,本文我们主要以这个来讲解,其他2种有兴趣的朋友可以去研究一下。

    Windows10中安装Nexus私服
    nexus是java开发的,所以运行的时候需要有java环境的支持。

    nexus下载和版本

    https://www.sonatype.com/nexus-repository-oss

    nexus-3.20.1-01-win64
    
    C:Usersjie>java -version
    java version "1.8.0_201"
    Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
    Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
    

    nexus启动

    nexus.exe /run

    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus.exe /run
    2020-01-23 20:52:01,237+0800 INFO  [FelixStartLevel] *SYSTEM org.sonatype.nexus.pax.logging.NexusLogActivator - start
    2020-01-23 20:52:03,362+0800 INFO  [FelixStartLevel] *SYSTEM org.sonatype.nexus.features.internal.FeaturesWrapper - Fast FeaturesService starting
    2020-01-23 20:56:54,923+0800 INFO  [jetty-main-1] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer -
    -------------------------------------------------
    
    Started Sonatype Nexus OSS 3.20.1-01
    
    -------------------------------------------------
    

    浏览器访问

    http://localhost:8081/

    其他版本可能需要输入:http://localhost:8081/nexus

    登录

    需要修改密码

    Your admin user password is located in
    D:chengxu
    exus-3.20.1-01-win64sonatype-work
    exus3admin.password on the server.
    

    修改启动端口

    默认端口是8081,如果和本机有冲突,可以在下面的文件中修改:

    ${dir}etc
    exus-default.properties
    

    nexus安装服务

    必须以管理员身份启动命令行,安装和启动服务。start是安装好服务后启动服务的,而run是不需要安装服务直接运行的。

    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus /install
    Installed service 'nexus'.
    
    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus /start
    Starting service 'nexus'.
    
    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus /status
    Running.
    Auto-start.
    
    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus /status
    Running.
    Auto-start.
    
    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus --help
    Usage: nexus.exe /install | /uninstall | /stop | /start | /status | /run | /run-redirect
    
    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus /start
    Could not start service. Error code: 1060
    
    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus /install
    Could not open SCManager.
    

    nexus仓库类型

    上图中是nexus安装好默认自带的仓库列表,主要有3种类型:
    
    代理仓库
    
    宿主仓库
    
    仓库组
    

    下载组件

    • settings.xml文件中设置一个server
    • pom.xml中设置仓库,仓库的id和server的id是相同的。
    <server>
        <id>maven_mozq</id>
        <username>admin</username>
        <password>admin</password>
    </server>
    
    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.18</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>maven_mozq</id>
            <url>http://localhost:8081/repository/maven-public/</url>
        </repository>
    </repositories>
    
    D:01>mvn compile
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------< com.mozq.dubbo:demo-01-provider >-------------------
    [INFO] Building demo-01-provider 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    Downloading from maven_mozq: http://localhost:8081/repository/maven-public/com/alibaba/druid/1.1.18/druid-1.1.18.jar
    Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/com/alibaba/druid/1.1.18/druid-1.1.18.jar
    Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/com/alibaba/druid/1.1.18/druid-1.1.18.jar (2.8 MB at 645 kB/s)
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo-01-provider ---
    [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory D:01srcmain
    esources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo-01-provider ---
    [INFO] No sources to compile
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  35.810 s
    [INFO] Finished at: 2020-01-23T22:41:29+08:00
    [INFO] ------------------------------------------------------------------------
    
    D:01>mvn compile
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------< com.mozq.dubbo:demo-01-provider >-------------------
    [INFO] Building demo-01-provider 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    Downloading from maven_mozq: http://localhost:8081/repository/maven-public/com/alibaba/druid/1.1.18/druid-1.1.18.jar
    Downloading from central: https://repo.maven.apache.org/maven2/com/alibaba/druid/1.1.18/druid-1.1.18.jar
    Progress (1): 0.1/2.8 MB
    
    D:01>mvn compile
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------< com.mozq.dubbo:demo-01-provider >-------------------
    [INFO] Building demo-01-provider 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    Downloading from maven_mozq: http://localhost:8081/repository/maven-public/com/alibaba/druid/1.1.18/druid-1.1.18.jar
    Downloaded from maven_mozq: http://localhost:8081/repository/maven-public/com/alibaba/druid/1.1.18/druid-1.1.18.jar (2.8 MB at 103 kB/s)
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo-01-provider ---
    [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory D:01srcmain
    esources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo-01-provider ---
    [INFO] No sources to compile
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  28.263 s
    [INFO] Finished at: 2020-01-23T22:57:20+08:00
    [INFO] ------------------------------------------------------------------------
    

    上传组件

    • pom.xml中设置发布的快照仓库和稳定仓库。
    • settings.xml中设置快照和稳定的server。server的id和仓库的id保持相同。

    如果需要上传第3方的组件,则直接使用nexus界面进行上传操作。

    <?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>
    
        <groupId>com.mozq.common</groupId>
        <artifactId>date</artifactId>
        <version>1.0</version>
    
        <distributionManagement>
            <repository>
                <id>nexus-releases</id>
                <url>http://localhost:8081/repository/maven-releases/</url>
            </repository>
            <snapshotRepository>
                <id>nexus-snapshots</id>
                <url>http://localhost:8081/repository/maven-snapshots/</url>
            </snapshotRepository>
        </distributionManagement>
    </project>
    
    <server>
        <id>nexus-releases</id>
        <username>admin</username>
        <password>admin</password>
    </server>
    <server>
        <id>nexus-snapshots</id>
        <username>admin</username>
        <password>admin</password>
    </server>
    

    bugs

    不能启动nexus

    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus.exe
    
    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus.exe  /
    
    D:chengxu
    exus-3.20.1-01-win64
    exus-3.20.1-01in>nexus.exe  /start
    Could not start service. Error code: 1060
    方案:
    nexus.exe /run
    

    浏览器访问报404

    D:01>mvn compile
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------< com.mozq.dubbo:demo-01-provider >-------------------
    [INFO] Building demo-01-provider 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    Downloading from maven_mozq: http://localhost:8081/repository/maven-public/com/alibaba/druid/1.1.18/druid-1.1.18.pom
    Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/com/alibaba/druid/1.1.18/druid-1.1.18.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  13.567 s
    [INFO] Finished at: 2020-01-23T22:25:44+08:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project demo-01-provider: Could not resolve dependencies for project com.mozq.dubbo:demo-01-provider:jar:1.0-SNAPSHOT: Failed to collect dependencies at com.alibaba:druid:jar:1.1.18: Failed to read artifact descriptor for com.alibaba:druid:jar:1.1.18: Could not transfer artifact com.alibaba:druid:pom:1.1.18 from/to alimaven (http://maven.aliyun.com/nexus/content/groups/public/): maven.aliyun.com: Unknown host maven.aliyun.com -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
    

    ready to connect和manually blocked

    需要在仓库中将Block相关的选项去除勾选。
    1 Block outbound connections on the repository
    2 Auto-block outbound connections on the repository if remote peer is detected as unreachable/unresponsive
    等待连接状态不用管,使用的请求下载jar,就会自动变为remote available
    
  • 相关阅读:
    sql学习2----函数
    网络相关命令
    网络相关概念
    linux学习(2)--指令
    linux学习(1)--基本知识
    Linux学习技巧
    VMware安装Linux
    接口测试
    app测试--DDMS的使用
    app测试--性能测试DDMS
  • 原文地址:https://www.cnblogs.com/mozq/p/12231645.html
Copyright © 2011-2022 走看看