如何把自己的Jar包上传到 maven 官方仓库中,Maven上传图文讲解

JSON 2017-09-12 13:23:07 37687

本文来自本群内的(暴富的长风)同学提供原创稿,本人表示尊敬与尊重的发布和整理这篇原稿。互联网只要有原创存在,那就还是互联网。不扯了了,开车了。

之前有同学在本站发布过“Maven的Mirror和Repository 的详细讲解”,这种我们自己搭建仓库和私服,一般这种是服务于公司或者团体。但是针对小“ 团伙 ”或者单兵作战,或者我们希望开源,开发给其他人去用,那么我们可以直接提交到官方(maven.org ),然后dependency 去引入即可,如下图:

当然,上面是已经开源好的,在Maven公共库里面是存在的。

一、Maven中央仓库提交 · 前奏准备

开始要注意这个几个Maven相关地址:

https://issues.sonatype.org 工单管理地址,就是申请上传资格和groupId 的地方。

https://oss.sonatype.org/#welcome  构件仓库,把jar包上传到这里,Release 之后就会同步到maven中央仓库。

http://search.maven.org/  最终表现在可以在这里搜索到。

部分网址第一次打开有点慢,请稍等。

二、创建工单

https://issues.sonatype.org 注册一个帐号(已经有请忽略),账号密码要记住,下面登录账号密码还要用这个,后续还要配置  maven  的setting.xml 中,然后创建一个工单,如下图(记住是先注册,下面是创建工单的图)。

记住是先注册,再创建。

其中需要注意的地方:

Group Id ,唯一标识,我用的是com.github.xxxxx  如果用的是其他的比如:com.sojson.core 之类的,管理员会问你这个是不是属于你的网站,告诉他就可以了(用com.github.xxxxx 这种比较方便)。官方文档:http://central.sonatype.org/pages/choosing-your-coordinates.html

ProjectURL ,填项目源码的地址,官方有一篇文章说,如果不想公布源码,那么填写一个只含README 的项目的地址就可以了。

*其实管理员主要就是审核Group Id,其他的不重要

然后点击左侧列表中的Resolved recently 可以找到你刚创建的工单。

这时你的工单的状态Status Open ,等到审核通过状态会变为RESOLVED ,第一次审核要一天左右 ,因为时差原因,他们工作时间是我们的晚上,之后在创建工单如果GroupId 满足基本要求基本就是秒过。

三、配置Maven Settings.xml & pom.xml

1.配置  Maven  中的conf/settings.xml  ,然后在servers 中添加如下代码。

 <server>
    <id>sonatype-nexus-snapshots</id>
    <username>https://issues.sonatype.org的账号</username>
    <password>https://issues.sonatype.org的密码</password>
  </server>
  <server>
    <id>sonatype-nexus-staging</id>
    <username>https://issues.sonatype.org的账号</username>
    <password>https://issues.sonatype.org的密码</password>
  </server>

2.配置使用项目中的 pom.xml

<parent>
	<groupId>org.sonatype.oss</groupId>
	<artifactId>oss-parent</artifactId>
	<version>7</version>
</parent>

<licenses>
	<license>
		<name>The Apache Software License, Version 2.0</name>
		<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
		<distribution>repo</distribution>
	</license>
</licenses>

<!--写你自己的,这只是个例子-->
<scm>              
	<url> https://github.com/CallThink/Tools</url>
	<connection>https://github.com/CallThink/Tools.git</connection>
	<developerConnection>https://github.com/CallThink/Tools</developerConnection>
</scm>
<!--写你自己的,这只是个例子-->
<developers> 
	<developer>
		<name>changfeng</name>
		<email> changfeng @allytel.com.cn</email>
		<url>https://github.com/CallThink/Tools</url>
	</developer>
</developers>

四、GPG环境

我们需要一个GPG环境,用来对上传的文件进行加密和签名,保证你的jar包不被篡改,下载地址:https://www.gpg4win.org/

安装完成后 命令行窗口中输入 gpg –version 查看是否安装成功

成功后执行下列命令:

C:\Windows\system32>gpg --gen-key
gpg (GnuPG) 2.0.30; 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? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 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) 0
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: changfeng
Email address: 1010667394@qq.com
Comment: changfeng-chang
You selected this USER-ID:
    "changfeng (changfeng-chang) <1010667394@qq.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.
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: key EFFF81F9 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   3  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 3u
pub   2048R/EFFF81F9 2017-09-12
      Key fingerprint = B245 4560 4E6F EA74 FA7A  5ED2 5C48 1BA6 EFFF 81F9
uid       [ultimate] changfeng (changfeng-chang) <1010667394@qq.com>
sub   2048R/8477CCD1 2017-09-12

其中EFFF81F9 就是申请的key

过程中需要填写一个密码,记住他,下一步打包上传的时候需要它。

五、上传发布Jar到Maven中央仓库

BUILD SUCCESS成功之后执行下列命令(gpg --list-keys 命令可以查看自己的key)

C:\Windows\system32>gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 5C1845F3
gpg: sending key 5C1845F3 to hkp server keyserver.ubuntu.com

会在中间仓库中Staging Repositories 菜单中看到自己刚刚上传的jar 包,如果没有错的话,选中它然后点Release 就可以同步到中央仓库了,一般过十分钟左右就能在http://search.maven.org/上边搜到了。


版权所属:SO JSON在线解析

原文地址:https://www.sojson.com/blog/250.html

转载时必须以链接形式注明原始出处及本声明。

本文主题:

如果本文对你有帮助,那么请你赞助我,让我更有激情的写下去,帮助更多的人。

关于作者
一个低调而闷骚的男人。
相关文章
Springboot 打Jar包,Maven完美解决本地Jar包自动打入Springboot Jar
Maven的Mirror和Repository 的详细讲解
Plupload 上传详细讲解,Plupload 多实例上传,Plupload多个上传按钮
Shiro教程(二)Maven管理Shrio Jar
json-lib 的 maven dependency 引入及Jar包下载
不是Maven项目怎么引入Maven 方式的Jar包(七牛篇)
URL乱七八糟的字符讲解,来源以及如何解决
Springboot Maven 增加本地依赖包,Springboot Maven打包本地包
Springboot + Mybatis +Maven 自动生成 Mapper.xml,Entity,Dao。 generator 配置
七牛Maven项目使用,以及注意事项。
最新文章
PHP变量剖析 11
SQL全外连接剖析 119
SQL自然连接剖析 147
springboot启动原理 245
SQL右连接【RIGHT JOIN】详解及图解 450
SQL左链接【LEFT JOIN】详解及图解 357
SQL非等值连接剖析 262
SQL等链接剖析 291
SQL内连接详解及图解 385
python之numpy常用的100种数值相关方法及代码示例 231
最热文章
最新MyEclipse8.5注册码,有效期到2020年 (已经更新) 679241
苹果电脑Mac怎么恢复出厂系统?苹果系统怎么重装系统? 674561
免费天气API,全国天气 JSON API接口,可以获取五天的天气预报 599031
免费天气API,天气JSON API,不限次数获取十五天的天气预报 565278
Jackson 时间格式化,时间注解 @JsonFormat 用法、时差问题说明 551715
我为什么要选择RabbitMQ ,RabbitMQ简介,各种MQ选型对比 509186
Elasticsearch教程(四) elasticsearch head 插件安装和使用 479645
Jackson 美化输出JSON,优雅的输出JSON数据,格式化输出JSON数据... ... 262820
Java 信任所有SSL证书,HTTPS请求抛错,忽略证书请求完美解决 244092
Elasticsearch教程(一),全程直播(小白级别) 225127
支付扫码

所有赞助/开支都讲公开明细,用于网站维护:赞助名单查看

查看我的收藏

正在加载... ...