发布jar包到Maven中央仓库

2023-05-16

平时自己开发的工具类或者其他的框架的jar包一般都是放在本地。或者把代码上传到github让别人去下载然后自己打包。今天就说说如何把自己的jar包发布到Maven的中央仓库。让其他使用你的jar包的直接去中央仓库下载。如果你用的是阿里云的maven中央仓库。同样阿里云的中央仓库也会同步你的jar包。 
1 注册JIRA账号 
注册地址:https://issues.sonatype.org/secure/Dashboard.jspa 
2 创建 issue 
这里写图片描述
这些都是要填写的!

Project URL 和SCM url 可以填写自己github项目的地址 
Group ID 可以按自己需求填写,比如我填写的是com.ailikes

创建好以后 sonatype的工作人员审核处理,速度还是很快的,一般一个工作日以内,当Issue的Status变为RESOLVED后,就可以进行下一步操作了,否则,就等待
这里写图片描述
到了这里说明你已经能够去上传自己的jar包了 
3 配置maven Setting.xml文件 

 
添加Server节点

       <server>
            <id>自行替换</id>
            <username>替换成自己的JIRA账号</username>
            <password>替换成自己的JIRA账号密码</password>
        </server>

4 创建maven工程 
设置pom.xml文件

<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.ailikes</groupId>
	<artifactId>common-util</artifactId>
	<version>1.1.0-RELEASE</version>
	<name>common-util</name>
	<packaging>jar</packaging>
	<description>工具类工程</description>
	<url>https://github.com/AilikesXu/common-util.git</url>
	<developers>
	    <developer>
	            <name>ailikes</name>
	            <id>ailikes</id>
	            <email>15600499930@163.com</email>
	            <roles>
	                <role>Developer</role>
	            </roles>
	            <timezone>+8</timezone>
	        </developer>
	</developers>
	<licenses>
        <license>
            <name>Apache 2</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
            <comments>A business-friendly OSS license</comments>
        </license>
    </licenses>
    <scm>
        <url>https://github.com/AilikesXu</url>
        <connection>https://github.com/AilikesXu/common-util.git</connection>
    </scm>

	<properties>
		<argLine>-Dfile.encoding=UTF-8</argLine>
		<project-description>工具类工程</project-description>
		<java-version>1.7</java-version>
		<org.aspectj-version>1.8.4</org.aspectj-version>
		<org.slf4j-version>1.7.9</org.slf4j-version>
		<!-- 不加下面这一行会报错 [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! 增加之后 Using 'UTF-8' encoding to copy filtered resources. -->
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<org.springframework-version>4.1.4.RELEASE</org.springframework-version>
		<jetty.version>8.1.16.v20140903</jetty.version>
	</properties>
	<dependencies>
		<!-- java bean 验证 -->
		<dependency>
			<groupId>javax.validation</groupId>
			<artifactId>validation-api</artifactId>
			<version>1.1.0.Final</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-validator</artifactId>
		  	<version>5.4.1.Final</version>
		  	<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
	    <plugins>
	     	<plugin>
	            <groupId>org.apache.maven.plugins</groupId>
	            <artifactId>maven-compiler-plugin</artifactId>
	            <version>3.3</version>
	            <configuration>
	                <!-- 指定source和target的jdk版本是1.7 -->
	                <source>1.7</source>
	                <target>1.7</target>
	            </configuration>
	        </plugin>
		    <!-- 源码插件 -->
	  		<plugin>
	  			<groupId>org.apache.maven.plugins</groupId>
	  			<artifactId>maven-source-plugin</artifactId>
	  			<version>2.2.1</version>
	  			<!-- 发布时自动将源码同时发布的配置 -->
	  			<executions>
			    	<execution>
			    		<id>attach-sources</id>
			     		<goals>
			       			<goal>jar</goal>
			      		</goals>
			     	</execution>
			    </executions>
	  		</plugin>
	    </plugins>
	</build>
	<profiles>
        <profile>
            <id>release</id> <!-- 部署要用到 -->
            <build>
                <plugins>
                    <!-- Source -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>2.2.1</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- Javadoc -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- GPG -->
                     <plugin> <!-- 进行验签 -->
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <distributionManagement>
                <snapshotRepository>
                    <id>sonatype</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
                </snapshotRepository>
                <repository>
                    <id>sonatype</id>
                    <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                </repository>
            </distributionManagement>
        </profile>
    </profiles>
</project>


必须要的:name url description licenses scm
           <distributionManagement>                <snapshotRepository>
                    <id>oss</id><!-- settings.xml中server节点的id-->
                    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
                </snapshotRepository>
                <repository>
                    <id>oss</id>
                    <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                </repository>
            </distributionManagement>

5 windows环境安装gpg4win 
下载地址:https://www.gpg4win.org/download.html 
查看版本: 
这里写图片描述

$ gpg --gen-key
gpg (GnuPG) 1.4.19; Copyright (C) 2015 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection?
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) Y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"

Real name: ljbmxsm
Email address: ljbmxsm@gmail.com
Comment: flink-elasticsearch-connector
You selected this USER-ID:
    "iteblog (flink-elasticsearch-connector) <wyphao.2007@163.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
+++++
.+++++
gpg: /c/Users/iteblog/.gnupg/trustdb.gpg: trustdb created
gpg: key B15C5AA3 marked as ultimately trusted
public and secret key created and signed.

设置名字+邮箱,其他可以使用默认值,记住输入的passphrase,部署会用到 
6 上传密钥 
上传刚刚生成的秘钥 
这里写图片描述
上传命令

gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys CF21873A--上传到服务器
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys  CF21873A --查看是否上传整个
  • 1
  • 2

主要:keyserver.ubuntu.com:11371 现在这个是可用的,之前网上的pool.sks-keyservers.net 反正我上传成功但是在后面验证的时候不是用的这个地址。

7执行部署

mvn clean deploy -P release
  • 1

后面的release参数是 <id>release</id> <!-- 部署要用到 --> 这个

8 登录网站查看

地址:https://oss.sonatype.org 
用户名密码就是上面注册的。 
这里写图片描述
查看自己的(你定义的版本号不能带SNAPSHOT要不然看不到) 
a)构件准备好之后,在命令行上传构建;

b)在https://oss.sonatype.org/ “close”并“release”构件;

c)等待同步好(大约2小时多)之后,就可以使用了

9 通知管理员

去网站https://issues.sonatype.org 登录通知你的管理然后等待 
这里写图片描述
然后到这里就全部完成。剩下的就是等同步到中央仓库

看看我自己随便发布的一个结果: 
这里写图片描述
去中央仓库查看https://search.maven.org(中央仓库需要两个小时后) 
这里写图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

发布jar包到Maven中央仓库 的相关文章

随机推荐

  • wxpython记录生词GUI程序

    不使用数据库 实现一个简单的记生词软件 xff0c 基本功能包括 xff0c 添加新的生词及其中文含义 xff0c 浏览已经记录的单词 xff0c 随机选择部分单词进行复习 可考虑其它拓展的功能 这里使用wxpython的基本操作 xff0
  • 数据结构电视大赛投票系统

    电视大赛观众投票及排名系统的设计与实现 8学时 问题描述 xff1a 在很多的电视大赛中 xff0c 通常当选手表演结束后 xff0c 现场观众通过手中的按键对参赛选手进行投票 xff0c 然后对选手获得的票数进行统计 xff0c 从高到低
  • 监督学习与无监督学习

    机器学习如果按照训练样本标签的有无可以分为以下两种常用方法 有监督学习 supervised learning 和无监督学习 unsupervised learning 以机器学习中的分类 classification 来说 xff0c 输
  • Python授权码生成器(密码生成器)

    有时候我们需要为自己的产品设置一些使用权限 xff0c 这就需要随机授权码生成器 当然这是简单的随机生成器 xff0c 像Adobe这种授权码是需要一定的加密算法生成 xff0c 然后再验证授权码是否正确 xff0c 而不是简单的生成 本文
  • C语言赌博机掷骰子

    一个C语言写的小游戏 赌博机 xff0c 适合学习C语言的人学习借鉴 A C language to write a small game gambling machines suitable for learning C language
  • Linux基本命令

    由于参加了机器人社团 xff0c 涉足了Linux的知识 xff0c 今天开始写第一篇关于Linux的文章 Linux简介 xff08 百度百科 xff09 xff1a https baike baidu com item linux 27
  • 如何正确给锂电池充电

    刚给手机换了新电池 xff0c 发现很多人在手机和电脑充电方面存在着误区 xff0c 比如下面这个流言 流言 xff1a 新买的手机必须充满8小时以上并重复几次完全充电放电 xff0c 这个过程叫做激活 xff0c 这样可以使手机的电池达到
  • Python代码刷博客访问量

    寒假闲着无聊自习研究了一下Python爬虫与代理 就发现了一个很简单的刷博客访问量的技巧 首先 xff0c 我们设置一个代理池 xff0c 可以用数据库导入也可以简单的用一个数组 代理池可以从http www xicidaili com 选
  • eclipse svn 分支合并到主干

    首先需厘清SVN的分支以下几个概念 xff1a trunk 主干 可以理解为开发环境的代码 xff0c 平常做开发的工作目录 branches xff1a 从主干拷贝了一份代码重新在svn服务器上的建了个分支目录 通常叫branch xff
  • Python GUI程序整理

    文章目录 GUI程序 Python课程设计Windows系统资源探测器 Python密码存储器 wxpython简单记录生词GUI程序 python微博爬虫GUI程序 Python刷访问量GUI程序 Python弹球游戏 xff08 tki
  • 基于词典的社交媒体内容的情感分析(Python实现)

    之前写了一篇基于NLTK情感预测的文章http www omegaxyz com 2017 12 15 nltk emotion hilite 61 27NLTK 27b 更多内容访问omegaxyz com 情感词典是从微博 新闻 论坛等
  • 在Linux(Ubuntu)下编写编译C语言

    大家都知道在Windows中运行C语言很简单 xff0c 打开一个IDE xff08 VS或者codeblocks xff09 编写代码 xff0c 点击一个按钮就能运行了 在Linux中 xff0c 大家不怎么习惯用IDE xff0c 更
  • 提高C++运行效率的方法

    一 尽量减少值传递 xff0c 多用引用来传递参数 至于其中的原因 xff0c 相信大家也很清楚 xff0c 如果参数是int等语言自定义的类型可能能性能的影响还不是很大 xff0c 但是如果参数是一个类的对象 xff0c 那么其效率问题就
  • 第十三次CCF CSP认证(2018年3月)真题跳一跳

    跳一跳 问题描述 近来 xff0c 跳一跳这款小游戏风靡全国 xff0c 受到不少玩家的喜爱 简化后的跳一跳规则如下 xff1a 玩家每次从当前方块跳到下一个方块 xff0c 如果没有跳到下一个方块上则游戏结束 如果跳到了方块上 xff0c
  • 第十三次CCFCSP认证(2018年3月)真题碰撞的小球

    问题描述 数轴上有一条长度为L xff08 L为偶数 的线段 xff0c 左端点在原点 xff0c 右端点在坐标L处 有n个不计体积的小球在线段上 xff0c 开始时所有的小球都处在偶数坐标上 xff0c 速度方向向右 xff0c 速度大小
  • 第十三次CCF CSP认证(2018年3月)真题URL映射

    问题描述 URL 映射是诸如 Django Ruby on Rails 等网页框架 web frameworks 的一个重要组件 对于从浏览器发来的 HTTP 请求 xff0c URL 映射模块会解析请求中的 URL 地址 xff0c 并将
  • 第十三次CCF CSP认证(2018年3月)真题棋局评估

    问题描述 Alice和Bob正在玩井字棋游戏 井字棋游戏的规则很简单 xff1a 两人轮流往3 3的棋盘中放棋子 xff0c Alice放的是 X xff0c Bob放的是 O xff0c Alice执先 当同一种棋子占据一行 一列或一条对
  • 第十三次CCF CSP认证(2018年3月)真题二次求和

    问题描述 给一棵 n 个节点的树 xff0c 用 1 到 n 的整数表示 每个节点上有一个整数权值 ai 再给出两个整数 L R 现在有 m 个操作 xff0c 每个操作这样描述 xff1a 给定树上两个节点 u v 和一个整数 d xff
  • 演化计算基本方法与思想

    生物系统中 xff0c 进化被认为是一种成功的自适应方法 xff0c 具有很好的健壮性 基本思想 xff1a 达尔文进化论是一种稳健的搜索和优化机制 大多数生物体是通过自然选择和有性生殖进行进化 自然选择决定了群体中哪些个体能够生存和繁殖
  • 发布jar包到Maven中央仓库

    平时自己开发的工具类或者其他的框架的jar包一般都是放在本地 或者把代码上传到github让别人去下载然后自己打包 今天就说说如何把自己的jar包发布到Maven的中央仓库 让其他使用你的jar包的直接去中央仓库下载 如果你用的是阿里云的m