美文网首页
【Maven私服三】:使用maven私服下载构件

【Maven私服三】:使用maven私服下载构件

作者: AIGame孑小白 | 来源:发表于2021-06-09 12:14 被阅读0次

使用maven私服下载构件

01.配置Maven的settings.xml

需要在< servers>节点中增加几个< server>配置信息。

<servers>
    <server>
    <id>tomcat7</id>
    <username>tomcat</username>
    <password>tomcat</password>
    </server>
    <server>
    <id>nexus-releases</id>
    <username>deployment</username>
    <password>deployment1234</password>
    </server>
    <server>
    <id>nexus-snapshots</id>
    <username>deployment</username>
    <password>deployment1234</password>
    </server>
</servers>

注意:需要把我们之前的< mirror>取消掉,因为我们现在要使用我们自己搭建的nexus私服。

<?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">

<localRepository>D:\MySoftware\Maven\repository</localRepository>

<servers>
        <server>
        <id>tomcat7</id>
        <username>tomcat</username>
        <password>tomcat</password>
        </server>
        <server>
        <id>nexus-releases</id>
        <username>deployment</username>
        <password>deployment1234</password>
        </server>
        <server>
        <id>nexus-snapshots</id>
        <username>deployment</username>
        <password>deployment1234</password>
        </server>
</servers>
<mirrors>
    <!-- <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror> -->
</mirrors>
<profiles>
    <profile>
        <id>mynexus</id>
        <activation>
        <!-- activeByDefault:活动状态:是否每次都去检查信息  -->
            <activeByDefault>false</activeByDefault>
            <jdk>1.7</jdk>
        </activation>
        <repositories>
        <!-- 普通版本库 -->
            <repository>
                <id>nexus</id>
                <url>http://192.168.17.128:8081/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>

        <pluginRepositories>
        <!-- 插件版本库 -->
            <pluginRepository>
                <id>nexus</id>
                <url>http://192.168.17.128:8081/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>
<!-- 激活配置信息 -->
<activeProfiles>
<activeProfile>mynexus</activeProfile>
</activeProfiles>
</settings>

02.刷新Eclipse中的配置信息

接下来去Eclipse中刷新Maven配置信息:


03.编写顶级父工程的pom配置信息

新建一个maven的空项目,编写pom的配置文件:

<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>test</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    
    <dependencies>
        <dependency>
               <groupId>org.springframework</groupId>
               <artifactId>spring-context</artifactId>
               <version>4.1.6.RELEASE</version>
        </dependency>
    </dependencies>
    <!-- 下载 -->
    <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus Realses Repository</name>
            <url>http://192.168.17.128:8081/nexus/conten/repositories/realeases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Realses Repository</name>
            <url>http://192.168.17.128:8081/nexus/conten/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
    <!-- 上传 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <!-- 提供上传源代码 -->
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1.2</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

(在公司中)一般来说,这样的配置文件因该在顶级的父工程中编写配置,然后其子工程自动依赖。

接下来运行一下(install)


构建成功,但是还是和maven的私服没啥关系。

04.使用自己的私服

我们先去nexus的网页界面随便搜索一个jar


然后复制粘贴:


配置完成以后,继续maven install一下,就可以看到我们的maven开始访问本地私服啦:


相关文章

  • 【Maven私服三】:使用maven私服下载构件

    使用maven私服下载构件 01.配置Maven的settings.xml 需要在< servers>节点中增加几...

  • 搭建Maven私服-Nexus

    Maven 私服,可以代理远程仓库和部署自己或第三方构件。本文介绍使用最广泛搭建 Maven 私服的工具: Son...

  • Maven私服搭建

    什么是maven私服? 工程中如何使用? 如何接入maven私服? 了解maven私服 分为本地和远程 远程包括:...

  • Linux 下搭建 Sonatype Nexus Maven 私

    一、为什么需要搭建mave私服 如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven...

  • [Maven专题-03] -Maven私服构建

    私服概述 私服是一种特殊的远程仓库,它一般假设在公司局域网内。当Maven下载构件时从私服上取,如果不存在则私服从...

  • maven私服

    1、配置本地maven settings.xml 使用私服 2、发布jar到私服配置本地maven setting...

  • maven私服管理

    maven工程使用私服中需要添加repository 私服会有密码,所以需要在maven的settings文件中加...

  • Maven私服-Nexus搭建

    1. 为什么使用Nexus? 如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓...

  • Maven(5)Nexus

    前言 Maven是Java项目管理的利器,使用私服来管理Maven仓库是Maven使用的一条最佳实践。私服是内网的...

  • Maven私服实战

    Maven私服实战 前置依赖 JDK Maven 下载 Nexus Repository Manager OSS ...

网友评论

      本文标题:【Maven私服三】:使用maven私服下载构件

      本文链接:https://www.haomeiwen.com/subject/ozsceltx.html