maven 私服搭建 For Windows

说明

文中使用的 Nexus 版本为:nexus-3.26.1-02

一、下载Nexus

官网的下载速度很慢,可以从百度网盘下载

二、安装配置Nexus

安装Nexus,nexus3.0之后的所有windows版本,都是免安装,只需开启服务就行。安装方法和2.x版本还是有区别的

2.1 安装 Nexus

2.1.1 解压

将下载好的压缩包nexus-3.26.1-02-win64.zip解压到指定的目录,这是我的目录E:\nexus-3.26.1-02-win64
在这里插入图片描述

  • nexus-3.26.1-02      nexus 的服务目录
  • sonatype-work         私服库目录
2.1.2 安装 Nexus 服务
  1. 以管理员身份打开 cmd命令行窗口
  2. cdnexus-3.26.1-02目录的 bin 目录下
C:\Windows\System32>e:
E:\>cd nexus-3.26.1-02-win64/nexus-3.26.1-02/bin
E:\nexus-3.26.1-02-win64\nexus-3.26.1-02\bin>
  1. 安装服务
E:\nexus-3.26.1-02-win64\nexus-3.26.1-02\bin>nexus.exe /install
Installed service 'nexus'. // 安装成功

此时在windows的服务列表可以看到 nexus 的服务
在这里插入图片描述

  1. 启动服务
    两种方式:
    nexus.exe /run
    nexus.exe /start
  • nexus.exe /run
    此方式为前台启动,启动后无法关闭dos窗口
E:\nexus-3.26.1-02-win64\nexus-3.26.1-02\bin>nexus.exe /run

在这里插入图片描述
启动过程大概需要1分钟,出现下面的信息,启动成功:
在这里插入图片描述

  • nexus.exe /start
    此方式为后台启动,启动后可以关闭dos窗口
E:\nexus-3.26.1-02-win64\nexus-3.26.1-02\bin>nexus.exe /start
Starting service 'nexus'. // 启动成功
E:\nexus-3.26.1-02-win64\nexus-3.26.1-02\bin>
  1. 访问http://127.0.0.1:8081/
    在这里插入图片描述
    在这里插入图片描述
    提示管理员用户(admin)密码位于服务器上 E:\nexus-3.26.1-02-win64\sonatype-work\nexus3\admin.password 的文件中。在之前的其他版本中默认的账号为admin,密码为admin123在这里插入图片描述
    用 notepad 或者 记事本 打开文件E:\nexus-3.26.1-02-win64\sonatype-work\nexus3\admin.password ,并复制出密码。
    在这里插入图片描述
    在这里插入图片描述
    填写 账号:admin,密码:c845fec8-826f-481a-aa59-f7ac4ea00f25,点击 sigin in
    在这里插入图片描述
    进入安装引导,点 Next
    在这里插入图片描述

输入新密码,点 Next,设置好密码后 admin.password 文件会被删除
在这里插入图片描述
在这里插入图片描述
配置匿名访问
在这里插入图片描述

Enable anonymous access means that by default, users can search, browse and download components from repositories without credentials. Please consider the security implications for your organization.
(启用匿名访问意味着默认情况下,用户可以在没有凭据的情况下从存储库中搜索、浏览和下载组件。请考虑对组织的安全影响。)


Disable anonymous access should be chosen with care, as it will require credentials for all users and/or build tools.
(应小心选择禁用匿名访问,因为它将需要所有用户和/或生成工具的凭据。)

配置完成,点 Finish
在这里插入图片描述
此时没有上传任何组件
在这里插入图片描述.

2.2 配置 Nexus

2.2.1 创建账号
2.2.2 配置 Respositories (仓库)

在这里插入图片描述

1. 说明
Nexus 的仓库分为三类:

  • porxy 远程代理仓库
    这种类型的仓库,可以设置一个远程仓库的链接。当用户向 proxy 类型仓库请求下载一个依赖构件时,就会先在自己的库里查找,如果找不到的话,就会从设置的远程仓库下载到自己的库里,然后返回给用户,相当于起到一个中转的作用。
    nexus默认的代理仓库为 Maven 的中央仓库(https://repo1.maven.org/maven2/),拉取速度比较慢,我们可以配置阿里的中央仓库,提高拉取速度。

  • hosted 本地仓库
    本地仓库,通常我们会部署自己的构件到这一类型的仓库,比如公司的二方库。分为两类,一类是release发布版,也就是正式版。一类是snapshot快照版。
    release 仓库不能重复上传同一版本号,版本不能覆盖,只能迭代,所以开发的稳定版本可以统一放置在release仓库中,其实可以配置为可重新部署。
    snapshot 仓库允许版本覆盖,当多次上传同一个版本到 snapshot 仓库,会自动在版本号上添加时间戳来区分。建议在开发测试时使用。

  • group 聚合仓库
    将多个仓库(hosted/porxy)聚合到同一个group中,使用中统一指定聚合仓库的仓库地址可以获取到同一group下的所有包,免去多仓库多地址的配置繁琐。

2. 创建阿里的镜像仓库,类型为 Proxy

点击 create repository
因为 Nexus 默认的仓库为 maven 的中央库,拉取速度慢,所以我们需要配置阿里的仓库镜像,提高拉取第三方库的速度。

在这里插入图片描述
选择 maven2(proxy)

在这里插入图片描述
填写配置信息

在这里插入图片描述

重要的配置如图中所示,其他的默认
阿里maven仓库地址:https://maven.aliyun.com/mvn/view
在这里插入图片描述

点击下面的 Create repository 完成创建
在这里插入图片描述
在这里插入图片描述

3. 配置 maven-releases 仓库为允许重新部署
这一步可以不用设置,不设置的话,仓库不能重复上传同一版本号,版本不能覆盖,只能迭代。

点击 maven-releases

在这里插入图片描述
修改为 Allow redeploy 可重新部署

在这里插入图片描述
点击 save 保存

在这里插入图片描述

4. 配置 maven-public 仓库

点击 maven-public 仓库
在这里插入图片描述
将刚刚创建的 maven-aliyun 仓库添加到 maven-public 聚合仓库中
在这里插入图片描述
调整 maven-aliyun 在组中的位置
因为拉取组件的顺序是从上往下的,如果 maven-releases 中没有,会从 maven-snapshots 中找,以此类推。而 maven-central 仓库代理仓库是maven的中央库,速度比较慢,所以要把 maven-aliyun 的镜像仓库地址放到 maven-central 仓库上面。

在这里插入图片描述

三、配置本地 maven 的 Setting.xml

3.1 配置文件地址

${maven_home}/conf/setting.xml

3.2 完整配置文件

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<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">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <!-- 该值表示构建系统本地仓库的路径。 -->
  <localRepository>E:\maven\repository</localRepository>

  <!-- interactiveMode
   | 
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
   
  <interactiveMode>true</interactiveMode>
  -->
  <!--表示maven是否需要和用户交互以获得输入如果maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。-->
  <interactiveMode>true</interactiveMode>

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <!-- 在pluginGroups元素下面可以定义一系列的pluginGroup元素。表示当通过plugin的前缀来解析plugin的时候到哪里寻找。pluginGroup元素指定的是plugin的groupId。默认情况下,Maven会自动把org.apache.maven.plugins 和 org.codehaus.mojo 添加到pluginGroups下。 -->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <!-- 一般,仓库的下载和部署是在pom.xml文件中的repositories 和 distributionManagement 元素中定义的。然而,一般类似用户名、密码(有些仓库访问是需要安全认证的)等信息不应该在pom.xml文件中配置,这些信息可以配置在 settings.xml 中。 -->
  <servers>
    <!--	
	 | server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
	<!--服务器元素包含配置服务器时需要的信息 -->
	<server>
	  <!--这是server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。 -->
      <id>maven-releases</id>
	  <!--鉴权用户名。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。 -->
      <username>admin</username>
	  <!--鉴权密码 。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。密码加密功能已被添加到2.1.0 +。详情请访问密码加密页面 -->
      <password>admin123</password>
	  <!--鉴权时使用的私钥位置。和前两个元素类似,私钥位置和私钥密码指定了一个私钥的路径(默认是${user.home}/.ssh/id_dsa)以及如果需要的话,一个密语。将来passphrase和password元素可能会被提取到外部,但目前它们必须在settings.xml文件以纯文本的形式声明。 -->
      <!-- <privateKey>${usr.home}/.ssh/id_dsa</privateKey> -->
	  <!--鉴权时使用的私钥密码。 -->
      <!-- <passphrase>some_passphrase</passphrase> -->
      <!--文件被创建时的权限。如果在部署的时候会创建一个仓库文件或者目录,这时候就可以使用权限(permission)。这两个元素合法的值是一个三位数字,其对应了unix文件系统的权限,如664,或者775。 -->
      <!-- <filePermissions>664</filePermissions> -->
      <!--目录被创建时的权限。 -->
      <!-- <directoryPermissions>775</directoryPermissions> -->
    </server>
	<server>
      <id>maven-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <!-- 
  用于定义一系列的远程仓库的镜像。我们可以在pom中定义一个下载工件的时候所使用的远程仓库。
  但是有时候这个远程仓库会比较忙,所以这个时候人们就想着给它创建镜像以缓解远程仓库的压力,
  也就是说会把对远程仓库的请求转换到对其镜像地址的请求。每个远程仓库都会有一个id,
  这样我们就可以创建自己的mirror来关联到该仓库,那么以后需要从远程仓库下载工件的时候Maven
  就可以从我们定义好的mirror站点来下载,这可以很好的缓解我们远程仓库的压力。在我们定义的mirror
  中每个远程仓库都只能有一个mirror与它关联,也就是说你不能同时配置多个mirror的mirrorOf指向同
  一个repositoryId。
  -->
  <mirrors>
     <!-- 给定仓库的下载镜像。 -->
     <mirror>
	  <!-- 该镜像的唯一标识符。id用来区分不同的mirror元素。 -->
      <id>nexus</id>
	  <!-- 镜像名称 -->
      <name>nexus-repository</name>
	  <!-- 被镜像的服务器的id。例如,如果我们要设置了一个Maven中央仓库(http://repo.maven.apache.org/maven2/)的镜像,就需要将该元素设置成central。这必须和中央仓库的id central完全一致。 -->
      <mirrorOf>central</mirrorOf>
	  <!-- 该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL。 -->
	  <url>http://localhost:8081/repository/maven-public/</url>
    </mirror>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
	<profile>
	  <id>dev</id>
	  <!-- 
	  用于定义远程仓库的,当该profile是激活状态的时候,
	  这里面定义的远程仓库将作为当前pom的远程仓库。它是maven
	  用来填充构建系统本地仓库所使用的一组远程仓库。
	  -->
	  <repositories>  
		  <repository>
			<!--远程仓库唯一标识 -->
			<id>maven-public</id>
			<!--远程仓库名称 -->
			<name>maven-public</name>  
			<!--仓库地址-->  
			<url>http://localhost:8081/repository/maven-public/</url>    
			<!--如何处理远程仓库里快照版本的下载。有了releases和snapshots这两组配置,POM就可以在每个单独的仓库中,为每种类型的构件采取不同的策略。例如,可能有人会决定只为开发目的开启对快照版本下载的支持。参见repositories/repository/releases元素 -->
			<snapshots>     
				<!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
				<enabled>true</enabled>   
				<!--该元素指定更新发生的频率。Maven会比较本地POM和远程POM的时间戳。这里的选项是:always(一直),daily(默认,每日),interval:X(这里X是以分钟为单位的时间间隔),或者never(从不)。 -->
				<updatePolicy>always</updatePolicy>
				<!--当Maven验证构件校验文件失败时该怎么做-ignore(忽略),fail(失败),或者warn(警告)。 -->
				<checksumPolicy>warn</checksumPolicy>
			</snapshots>
			<!--如何处理远程仓库里发布版本的下载 -->
			<releases>      
				<!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
				<enabled>true</enabled>   
				<!--该元素指定更新发生的频率。Maven会比较本地POM和远程POM的时间戳。这里的选项是:always(一直),daily(默认,每日),interval:X(这里X是以分钟为单位的时间间隔),或者never(从不)。 -->
				<!-- <updatePolicy>always</updatePolicy> -->
				<!--当Maven验证构件校验文件失败时该怎么做-ignore(忽略),fail(失败),或者warn(警告)。 -->
				<!-- <checksumPolicy>warn</checksumPolicy> --> 
			</releases>  
		  </repository>
	  </repositories>
	  <pluginRepositories>  
	    <pluginRepository>  
		  <!--插件地址--> 
		  <id>nexus-public</id>  
		  <url>http://localhost:8081/repository/maven-public/</url>  
	    </pluginRepository>
	  </pluginRepositories>
	</profile>
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
  <activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>
</settings>


四、创建二方库

4.1 使用 IDEA 创建一个 maven 项目

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4.2 配置 maven 的 setting.xml 为我们的私服库

File -> settings -> Build, Execution, Deployment -> Build Tools -> Maven
在这里插入图片描述
settings-local.xml 就是我们的私服配置

4.3 编辑 pom.xml 文件

完整 pom

<?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.avatar</groupId>
    <artifactId>maven-component</artifactId>
    <version>1.0-SNAPSHOT</version>

	<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- 测试第三方库 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.8.1</version>
        </dependency>
    </dependencies>

    <!-- 配置远程发布到私服,mvn deploy -->
    <distributionManagement>
        <!-- repository 即可以配置 releases 仓库,也可以配置 snapshots 仓库 -->
        <repository>
            <!-- id 必须和 nexus上的name一致 -->
            <id>maven-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://localhost:8081/repository/maven-releases/</url>
        </repository>
        <!-- 配置 snapshot 仓库 -->
        <snapshotRepository>
            <id>maven-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://localhost:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
    <plugins>
    
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.0.1</version>
            <configuration>
                <attach>true</attach>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
       </plugin>
  </plugins>

</project>

4.4 maven发布组件

在这里插入图片描述
出现如下显示,说明发布成功
在这里插入图片描述
此时查看nexus服务,可以看到在 maven-snapshots 仓库中出现了我们发布的快照版本的组件
在这里插入图片描述
将 pom 中的版本号中的 1.0-SNAPSHOT改为1.0-RELEASE,重新发布

在这里插入图片描述
此时查看nexus服务,可以看到在 maven-snapshots 仓库中出现了我们发布的正式版组件
在这里插入图片描述
接下来测试从我们的maven私服中拉取刚刚发布的组件

五、通过私服下载二方库

5.1 使用 IDEA 创建一个maven项目

项目名 maven-demo,此过程不在演示

5.2 设置此项目 maven 的 settings.xml 配置

File -> settings -> Build, Execution, Deployment -> Build Tools -> Maven
在这里插入图片描述

5.3 编辑 pom.xml 文件

在maven私服中查找我们上传的组件
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
编辑pom文件

<?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.avatar</groupId>
    <artifactId>maven-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.avatar</groupId>
            <artifactId>maven-component</artifactId>
            <version>1.0-RELEASE</version>
        </dependency>
    </dependencies>

</project>

5.4 编写测试类

package com.avatar.maven;

/**
 * @author wangpeng
 * @date 2020/9/1 23:23
 */
public class TestMain {

    public static void main(String[] args) {
        System.out.println(Test.equals("A", "B"));
        System.out.println(Test.sayHi("avatar"));
    }
}

运行结果如下,说明我们开发的二方库已经被拉取了。
在这里插入图片描述

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值