如何把jar包发布发布jar到mavenn私服

如何发布Jar包到Maven中央仓库 – 过往记忆
欢迎关注Hadoop、Spark、Flink、Hive、Hbase、Flume等大数据资料分享微信公共账号:iteblog_hadoop。
文章总数:859
浏览总数:10,515,689
评论:4880
分类目录:95 个
注册用户数:2671
最后更新:日
欢迎关注微信公共帐号:iteblog_hadoop
大数据猿:bigdata_ai
  本博客曾经介绍了这里的方法非常的简单,而且局限性很大:只能提供给本人开发使用,无法共享给其他需要的人。本文将介绍如何把自己开发出来的Java包发布到中央仓库(),这样任何人都可以搜索到这个包并使用它。如果你现在还不了解是啥东西,请你先找本书看看。
  将自己的Java包发布到Maven中央仓库需要经过许多繁琐的步骤,本文将详细地介绍这些步骤。相信大家在看完本文之后也会发布jar包到Maven中央仓库。
  在发布Java包到Maven中央仓库首先需要在网站创建一个工单(Issues),第一次使用这个网站的时候需要注册自己的帐号(这个帐号和密码需要记住,后面会用到),之后创建自己的Issue,点击导航最上面的Create按钮,然后会弹出下面的对话框,将Project和Issue Type设置为下图的内容:
如果想及时了解Spark、Hadoop或者Hbase相关的文章,欢迎关注微信公共帐号:iteblog_hadoop
然后根据你Java包的功能分别写上Summary、Description、Group Id、SCM url以及Project URL等必要信息,可以参见我之前创建的Issue:。创建完之后需要等待Sonatype的工作人员审核处理,审核时间还是很快的,我的审核差不多等待了两小时。当Issue的Status变为RESOLVED后,就可以进行下一步操作了。
  如果你的Group Id填写的是自己的网站(我的就是这种情况),Sonatype的工作人员会询问你那个Group Id是不是你的域名,你只需要在上面回答是就行,然后就会通过审核。
使用gpg生成密钥对
上面创建的issuce经过审核之后,我们可以使用gpg生成密钥对,这里分两种情况:
  1、如果使用的是Windows,可以到下载gpg4win,推荐使用 Gpg4win-Vanilla 2.3.3版本,因为它仅包括 GnuPG,这个工具才是我们所需要的;
  2、如果使用的是Linux,可以通过yum install gpg命令安装gpg。
之后可以通过gpg --version命令查看是否安装成功,如果出现版本等信息说明安装成功了,如下:
[iteblog@ ~] $ gpg --version
gpg (GnuPG) 2.0.14
libgcrypt 1.4.5
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later &http://gnu.org/licenses/gpl.html&
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA
Cipher: 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH, CAMELLIA128,
CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
安装完gpg之后,下面一次按照如下的命令设置好你的名字,邮箱,其他步骤可以使用默认值。不过输入Passphrase的值需要记住,这个相当于密钥的密码,发布过程中进行签名操作的时候会用到:
$ 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
= 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
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: iteblog
Email address: wyphao.
Comment: flink-elasticsearch-connector
You selected this USER-ID:
&iteblog (flink-elasticsearch-connector) &wyphao.&&
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
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.
gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0
trust: 0-, 0q, 0n, 0m, 0f, 1u
2048R/B15C5AA3
Key fingerprint = DB61 0E 20E7
iteblog (flink-elasticsearch-connector) &wyphao.&
到这里我们就设置好密钥对了。上面代码中导数第四行的B15C5AA3需要记住,其相当于我们生成的key,后面会用到。
设置Maven配置
为了发布更简便,我们可以工程的pom.xml文件里面加入以下的配置:
&groupId&org.sonatype.oss&/groupId&
&artifactId&oss-parent&/artifactId&
&version&7&/version&
并增加Licenses、SCM、Developers信息:
&licenses&
&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&
&url&//flink-elasticsearch2-connector&/url&
&connection&:/flink-elasticsearch2-connector.git&/connection&
&developerConnection&&/developerConnection&
&developers&
&developer&
&name&iteblog&/name&
&email&wyphao.&/email&
&url&&/url&
&/developer&
&/developers&
最后修改Maven的setting.xml配置文件,设置如下:
&id&sonatype-nexus-snapshots&/id&
&username&Sonatype网站的账号&/username&
&password&Sonatype网站的密码&/password&
&id&sonatype-nexus-staging&/id&
&username&Sonatype网站的账号&/username&
&password&Sonatype网站的密码&/password&
&/servers&
上面的username和password就是你在步骤一注册的帐号和密码。
部署和发布Jar包
配置好pom.xml文件和Maven的setting.xml文件之后,我们就可以部署Jar包了,运行如下命令:
$ mvn clean deploy -P sonatype-oss-release -Darguments=&gpg.passphrase=设置gpg设置密钥时候输入的Passphrase&
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building flink-elasticsearch2-connector 1.0.1
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ flink-elasticsearch2-connector ---
[INFO] Deleting D:\work\flink-elasticsearch2-connector\target
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ flink-elasticsearch2-connector ---
[INFO] --- maven-source-plugin:2.1.2:jar-no-fork (attach-sources) @ flink-elasticsearch2-connector ---
[INFO] --- maven-javadoc-plugin:2.7:jar (attach-javadocs) @ flink-elasticsearch2-connector ---
[INFO] Not executing Javadoc as the project is not a Java classpath-capable package
[INFO] --- maven-gpg-plugin:1.1:sign (sign-artifacts) @ flink-elasticsearch2-connector ---
GPG Passphrase: *****************
[INFO] --- maven-install-plugin:2.4:install (default-install) @ flink-elasticsearch2-connector ---
[INFO] Installing D:\work\flink-elasticsearch2-connector\pom.xml to D:\q\repos\com\iteblog\flink-elasticsearch2-connector\1.0.1\flink-elasticsearch2-connector-1.0.1.pom
[INFO] Installing D:\work\flink-elasticsearch2-connector\target\flink-elasticsearch2-connector-1.0.1.pom.asc to D:\q\repos\com\iteblog\flink-elasticsearch2-connector\1.0.1\flink-elasticsearch2-connector-1.0.1.pom.asc
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ flink-elasticsearch2-connector ---
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/iteblog/flink-elasticsearch2-connector/1.0.1/flink-elasticsearch2-connector-1.0.1.pom
Uploaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/iteblog/flink-elasticsearch2-connector/1.0.1/flink-elasticsearch2-connector-1.0.1.pom (4 KB at 0.4 KB/sec)
Downloading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/iteblog/flink-elasticsearch2-connector/maven-metadata.xml
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/iteblog/flink-elasticsearch2-connector/maven-metadata.xml
Uploaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/iteblog/flink-elasticsearch2-connector/maven-metadata.xml (321 B at 0.0 KB/sec)
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/iteblog/flink-elasticsearch2-connector/1.0.1/flink-elasticsearch2-connector-1.0.1.pom.asc
Uploaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/iteblog/flink-elasticsearch2-connector/1.0.1/flink-elasticsearch2-connector-1.0.1.pom.asc (473 B at 0.1 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.272s
[INFO] Finished at: Mon Sep 19 14:15:21 CST 2016
[INFO] Final Memory: 21M/224M
[INFO] ------------------------------------------------------------------------
运行上面的命令之后,我们再上传到第三方的key验证库,如下:
$ gpg --list-keys
/c/Users/iteblog/.gnupg/pubring.gpg
---------------------------------------
2048R/B15C5AA3
iteblog (flink-elasticsearch-connector) &wyphao.&
iteblog@iteblog MINGW64 /d/work/flink-elasticsearch2-connector (master)
$ gpg --keyserver hkp://:11371 --send-keys B15C5AA3
gpg: sending key B15C5AA3 to hkp server
之后我们的Java包将会发布到sonatype的构件仓库中,可以到查看发布好的Jar。进入之后会看到中间一个Table窗口,将滑动条移到最后,找到我们刚刚发布的Jar包,然后依次点击上方的Close–>Confirm,这将会弹出类似于下面的对话框,在其中输入我们Jar包的描述信息,这个信息将会在Maven搜索结果当作简介介绍我们Jar包的,所以建议输的详细点。
如果想及时了解Spark、Hadoop或者Hbase相关的文章,欢迎关注微信公共帐号:iteblog_hadoop
当状态变成closed后,执行Release–>Confirm,同样会弹出一个类似于上面的对话框,我们还是输入那些介绍信息即可,当这步执行完之后,构件将会自动删除,并经过几小时后便可以在Maven中央仓库搜索到()。如下:
如果想及时了解Spark、Hadoop或者Hbase相关的文章,欢迎关注微信公共帐号:iteblog_hadoop
网站的显示:
如果想及时了解Spark、Hadoop或者Hbase相关的文章,欢迎关注微信公共帐号:iteblog_hadoop
  我们开发的Jar包在后面可能需要更新,比如从1.0.1版本升级到1.0.2版本。升级Jar包比初次发布的步骤简单的多,我们只需要更新项目工程代码,并修改pom.xml文件里面的版本号,最后重新执行上面的部署和发布Jar包步骤即可。
优秀人才不缺工作机会,只缺适合自己的好机会。但是他们往往没有精力从海量机会中找到最适合的那个。
100offer 会对平台上的人才和企业进行严格筛选,让「最好的人才」和「最好的公司」相遇。
注册 100offer,谈谈你对下一份工作的期待。一周内,收到 5-10 个满足你要求的好机会!
本博客文章除特别声明,全部都是原创!
禁止个人和公司转载本文、谢谢理解:
下面文章您可能感兴趣25709人阅读
1.格式
&mvn deploy:deploy-file -DgroupId=com.qiyi -DartifactId=sphinx -Dversion=1.0 -Dpackaging=jar -Dfile=D:\sphinxapi.jar -Durl=[url] -DrepositoryId=[id
D:\develop\apache-maven-3.0.4\bin&mvn deploy:deploy-file -DgroupId=org.sphx -DartifactId=sphinxapi -Dversion=1.0 -Dpackaging=jar -Dfile=D:\sphinxapi.jar
-Durl=http://10.10.10.10:8800/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty
DgroupId和DartifactId构成了该jar包在pom.xml的坐标,项目就是依靠这两个属性定位。自己起名字也行。
Dfile表示需要上传的jar包的绝对路径。
Durl私服上仓库的位置,打开nexus——&repositories菜单,可以看到该路径。
DrepositoryId服务器的表示id,在nexus的configuration可以看到。
上传成功后,在nexus界面点击3rd party仓库可以看到这包。
3.配置权限
$MAVEN/conf/settings.xml
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:493469次
积分:3631
积分:3631
排名:第8964名
原创:63篇
转载:48篇
评论:39条
(13)(1)(7)(12)(2)(2)(2)(1)(4)(6)(1)(3)(8)(11)(1)(17)(10)(1)(1)(2)(1)(3)(2)上传jar包到maven库 - aawty - ITeye博客
博客分类:
情形:maven项目中经常会遇到项目需要的jar在中央库中没有。以百度云推送jar包为例。这时候我们有两种解决办法:
1.直接在本地库中install这个jar包。我们可以运行命令:
mvn install:install-file -DgroupId=baidu -DartifactId=bacc-api-lib -Dversion=1.1.2
-Dpackaging=jar -Dfile=E:\bccs-api-lib-1.1.2.jar
2.上传到本地仓库管理器Nexus中,它的好处是代理远程仓库的同时维护本地仓库,以节省带宽和时间。整个团队可以共享资源。例如我将包上传到Nexus中,其他人只要在本地库中配置有读取这个Nexus的资源的用户,就可以依赖这里面的包。具体配置是在settings.xml的&servers&&/servers&
&id&thirdparty&/id&
&username&admin&/username&&password&admin123&/password&
当然如果是上传包,就需要这个用户拥有上传的权限。上传的时候需要考虑仓库的类型,仓库分为:hosted、proxy、group、virtual四种类型。并且只能上传jar到hosted类型的仓库中。
但是如果依赖的仓库是group类型的,怎么上传呢?这时候如果直接向group类型的仓库中,会发现有return code为400的错误。其实group类型的仓库本身不包含资源,它只包含某些仓库,然后这些仓库中含有的资源合并在一起,你可以从中下载资源,但是不能直接上传jar包给他,只能上传到它包含的hosted类型的仓库中,就可以在这个组中访问到了。例如一个名为test group的组包含了hosted类型的3rd party仓库,将包上传到3rd party中就可以在test group中访问到这个包了。
上传的命令是:
mvn deploy:deploy-file -DgroupId=baidu -DartifactId=bacc-api-lib -Dversion=1.1.2 -Dpackaging=jar -Dfile=E:\bccs-api-lib-1.1.2.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty。
最后我们在项目的pom.xml文件中添加依赖就可以了:
&dependency&
&groupId&baidu&/groupId&
&artifactId&bacc-api-lib&/artifactId&
&version&1.1.2&/version&
&/dependency&
浏览: 10056 次
来自: 上海
cweiliang08 写道 加油呵呵 一起加油自使用maven以来,没少使用maven中央仓库中的各种jar包,方便有效,但是咱们也不能总是只取不予,也应该懂得奉献,当你写好了一个十分好用的jar包,想贡献出去给大家使用的时候,应该怎么做呢?当然是发布到maven的中央仓库了,不过要说这个发布过程,还真是比较复杂,本文就来详细说下如何发布jar包到maven中央仓库。&开始之前,请注意几个地址:&1、工单管理:
说明:注册账号、创建和管理issue,Jar包的发布是以解决issue的方式起步的
2、构件仓库:
说明:算是正式发布前的一个过段仓库,使用maven提交后的jar包先到这个库中
1、创建工单
在上述的工单管理的地址中进行创建,如果没有账号,需要先注册一个,记住用户名密码,后边要配置到setting.xml中。&Create Issue 填写内容说明:&
===Step 1===
Project:Community Support - Open Source Project Repository Hosting
Issue Type:New Project
===Step 2===
Summary:JAR包名称,如:marathon-client
Group Id:你懂得,不用多说,如com.cloudnil
Project URL:项目站点,如:https:
其他内容不用填写,创建Issue后需要等待一小段时间,Sonatype的工作人员审核处理,速度还是很快的,一般一个工作日以内,当Issue的Status变为RESOLVED后,就可以进行下一步操作了,否则,就等待&&
2、配置Maven
在工程的pom.xml文件中,引入Sonatype官方的一个通用配置oss-parent,这样做的好处是很多pom.xml的发布配置不需要自己配置了:
并增加Licenses、SCM、Developers信息:
修改maven配置文件setting.xml,在servers中增加server配置,找不到这个文件的同学请自己去旁边哭会先。
3、配置gpg-key
如果是使用的windows,可以下载gpg4win,地址:https://www.gpg4win.org/download.html,安装后在命令行中执行&gpg --gen-key生成,过程中需要填写名字、邮箱等,其他步骤可以使用默认值,不过有个叫:Passphase的参数需要记住,这个相当于是是密钥的密码,下一步发布过程中进行签名操作的时候会用到。&
这步就简单了,就是一套命令:
mvn clean deploy -P sonatype-oss-release -Darguments="gpg.passphrase=密钥密码"
如果使用eclipse的mvn插件发布的话,配置如下:&&如果发布成功,就可以到构件仓库中查看了。
5、Release
进入https://oss.sonatype.org/#stagingRepositories查看发布好的构件,点击左侧的Staging Repositories,一般最后一个就是刚刚发布的jar了,此时的构件状态为open。&打开命令行窗口,查看gpg key并上传到第三方的key验证库:
E:\98_code\workSpace\marathon-client&gpg --list-keys
C:/Users/VF/AppData/Roaming/gnupg/pubring.gpg
---------------------------------------------
2048R/824B4D7A 2016-01-06
[ultimate] cloudnil &cloudnil@126.com&
2048R/7A10AD69 2016-01-06
E:\98_code\workSpace\marathon-client&gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 824B4D7A
gpg: sending key 824B4D7A to hkp server keyserver.ubuntu.com
E:\98_code\workSpace\marathon-client&
回到https://oss.sonatype.org/#stagingRepositories,选中刚才发布的构件,并点击上方的close&&Confirm,在下边的Activity选项卡中查看状态,当状态变成closed后,执行Release&&Confirm,并在下边的Activity选项卡中查看状态,成功后构件自动删除,一小段时间(约1-2个小时)后即可同步到maven的中央仓库。
http://blog.csdn.net/tiger435/article/details/
/archives/1807.html
SCM Implementation: Git
General Info
License: GNU General Public License v2
For all URLs below, we use a colon (:) as separator. If you use a colon for one of the variables (e.g. a windows path), then use a pipe (|) as separator. The separator for the port has to be a colon in any case since this part is specified in the git URL specification. See man git-fetch.
scm:git:git://server_name[:port]/path_to_repository
scm:git:http://server_name[:port]/path_to_repository
scm:git:https://server_name[:port]/path_to_repository
scm:git:ssh://server_name[:port]/path_to_repository
scm:git:file://[hostname]/path_to_repository
scm:git:git:///path_to_repository
scm:git:/path_to_repository
scm:git:/path_to_repository
scm:git:ssh:///path_to_repository
scm:git:file://localhost/path_to_repository
Different Fetch and Push URLs
In some cases a different URL has to be used for read and write operations. This can happen if e.g. fetch is performed via the http protocol, but writing to the repository is only possible via ssh. In this case both URLs may be written into the&developerConnection&tag. The fetch URL has to be prefixed with&[fetch=]&and the push URL with&[push=]
&developerConnection&scm:git:[fetch=]http://mywebserver.org/path_to_repository[push=]ssh://username@otherserver:8898/~/repopath.git&/developerConnection&
Working with branches
Since version 1.3, we assume that the name of the branch in the upstream repo is the same as the name of the current local branch. So whenever you invoke a maven-scm action which has to access the upstream repository, e.g. start a release, you should be on that very branch.
In other words: If no branch is specified manually, every git-fetch, git-pull, git-push, etc will always work on the branch in the upstream repository which has the same branch name as your current local branch
git push pushUrl currentBranch:currentBranch
Provider Configuration
The provider configuration is defined in&$user.home/.scm/git-settings.xml.
&git-settings&
&!-- will had the option --no-verify to the commit command can be helpfull to ignore trailing spaces issues with cygwin and the release plugin --&
&commitNoVerify&false&/commitNoVerify&
&/git-settings&
http://maven.apache.org/scm/git.html
阅读(...) 评论()}

我要回帖

更多关于 jar包发布到maven仓库 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信