A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 84818684 中级黑马   /  2019-6-21 11:13  /  570 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

maven私服是搭建在公司局域网内的maven仓库,公司内的所有开发团队都可以使用。例如技术研发团队开发了一个基础组件,就可以将这个基础组件打成jar包发布到私服,其他团队成员就可以从私服下载这个jar包到本地仓库并在项目中使用。

将项目发布到maven私服操作步骤如下:

1. 配置maven的settings.xml文件

```xml
<server>
        <id>releases</id>
        <username>admin</username>   
        <password>admin123</password>
</server>
<server>
        <id>snapshots</id>
        <username>admin</username>
        <password>admin123</password>
</server>
```

​      注意:一定要在idea工具中引入的maven的settings.xml文件中配置

2. 配置项目的pom.xml文件

```xml
<distributionManagement>
        <repository>
                <id>releases</id>
        <url>http://localhost:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
                <id>snapshots</id>
        <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>
```

3. 执行mvn deploy命令

### 5.4 从私服下载jar到本地仓库

前面我们已经完成了将本地项目打成jar包发布到maven私服,下面我们就需要从maven私服下载jar包到本地仓库。

具体操作步骤如下:

在maven的settings.xml文件中配置下载模板
<profile>
        <id>dev</id>
                <repositories>
                <repository>
                        <id>nexus</id>
                <!--仓库地址,即nexus仓库组的地址-->
                        <url>
                        http://localhost:8081/nexus/content/groups/public/</url>
                <!--是否下载releases构件-->
                        <releases>
                        <enabled>true</enabled>
                        </releases>
                <!--是否下载snapshots构件-->
                        <snapshots>
                                <enabled>true</enabled>
                        </snapshots>
                </repository>
                </repositories>
<pluginRepositories>
        <!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
        <pluginRepository>
                <id>public</id>
                <name>Public Repositories</name>
                <url>
                http://localhost:8081/nexus/content/groups/public/</url>
                </pluginRepository>
                </pluginRepositories>
</profile>
在maven的settings.xml文件中配置激活下载模板
<activeProfiles>
        <activeProfile>dev</activeProfile>
</activeProfiles>

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马