zoukankan      html  css  js  c++  java
  • maven学习(4)-本地项目打包发布到私有仓库

    发布本地项目到私服仓库

    在前面章节有介绍maven发布本地jar包到私服仓库,这里详细介绍一下步骤。

    在项目开发中通常会引用其他的jar,怎样把自己的项目做为一个jar包的形式发布到私服仓库中,主要有以下三个步骤

    (怎样配置maven私服仓库,就不再这里说明了,可以参考以前的文章)1.在maven的setting.xml中配置用户名和密码:

    <servers>
        <server>
            <username>admin</username>
            <password>admin123</password>
            <id>nexus-release</id>
        </server>
        <server>
            <username>admin</username>
            <password>admin</password>
            <id>nexus-snapshots</id>
        </server>
    </servers>
    注意:要在nexus中打开相应的snapshots和releases仓库中的允许发布的开关

    2.在发布的项目中配置pom.xml 

    如果有parent只需在parent中的pom.xml中配置,没有则在本项目的pom.xml配置即可
    <distributionManagement>
    <repository>
    <id>nexus-release</id>
    <url>http://192.168.0.247/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
    <id>nexus-snapshots</id>
    <url>http://192.168.0.247/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
    </distributionManagement> <!--上传source.jar 非必须 -->
    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <executions>
    <execution>
    <id>attach-sources</id>
    <goals>
    <goal>jar</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>

    3.在依赖的项目添加依赖(注意版本是snapshot还是release)

    snapshot版本还是release版本取决于发布项目中的配置

    例如

    <properties>
    <!-- 依赖的版本定义 -->
    <mes.version>0.0.1-RELEASE</mes.version>
    </properties>
    <dependencies>
    <!-- 系统消息服务 -->
    <dependency>
    <groupId>com.longda.message</groupId>
    <artifactId>mes-core</artifactId>
    <version>${mes.version}</version>
    <type>jar</type>
    <scope>compile</scope>
    </dependency>

    </dependencies>

    相应的待发布项目中配置如下

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.longda.message</groupId>
    <artifactId>mes-core</artifactId>
    <version>0.0.1-RELEASE</version>
    <packaging>jar</packaging>
    <name>mes-core</name>
    <url>http://maven.apache.org</url>
    <properties>
    <project.release.version>0.1-RELEASE</project.release.version>

    </dependencies>

    注意:简而言之就是两边的版本一定要对应上,至于是发布snapshot版本还是release版本需要在第二步中指定

    maven中针对打包任务而提供的标准插件:assembly plugin。

  • 相关阅读:
    Kafka科普系列 | Kafka中的事务是什么样子的?
    RabbitMQ和Kafka,更加便捷高效的消息队列使用方式,请放心食用
    艰涩难懂,不存在的,消息队列其实很简单
    这七个关于分布式消息服务的常见问题,你知道吗?
    别再犯低级错误,带你了解更新缓存的四种Desigh Pattern
    详细介绍redis的集群功能,带你了解真正意义上的分布式
    教你简单理解分布式与传统单体架构的区别
    新手向:从不同的角度来详细分析Redis
    Java多线程Runnable与Callable区别与拓展
    项目中是用eCharts
  • 原文地址:https://www.cnblogs.com/weiguo21/p/3497468.html
Copyright © 2011-2022 走看看