首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

怎么将自己的jar包Release到Maven中央仓库中

2012-07-26 
如何将自己的jar包Release到Maven中央仓库中PS:真正要发布到Maven中央库中是首先需要到https://issues.son

如何将自己的jar包Release到Maven中央仓库中
PS:真正要发布到Maven中央库中是首先需要到https://issues.sonatype.org这里注册账号,新建一个issue,然后等待审核。审核通过后下一步就是等待你的release了,release的方式有好多种,其中有执行运行mvn命令的,但是那个命令结合gpg签名的时候中间会出现无限挂起的bug,我自己就遇到了,按照有关教程的说法要加个什么参数在pom中,但是还是没法解决,最后我就只能使用上传artifact为bundle的方式来release了。也就是下面说的这几个步骤。
  下载安装GPG工具,直到在cmd下运行下面命令,出现版本信息    

     gpg --version

  生成属于你自己的签名,并发送到公开保存的服务器上,例如美国的那个XX大学  下载安装Maven  保证你的项目pom至少包含下面这些信息    
<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.0http://maven.apache.org/maven-v4_0_0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>com.sonatype.sample</groupId>  <artifactId>sample-project</artifactId>  <packaging>jar</packaging>  <version>1.0</version>  <name>sample-project</name>  <description>A Sample Project for the Nexus Book</description>  <url>http://books.sonatype.com</url>  <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>    <connection>      scm:git:git://github.com/sonatype/sample-project.git    </connection>    <url>scm:git:git://github.com/sonatype/sample-project.git</url>    <developerConnection>      scm:git:git://github.com/sonatype-sample-project.git    </developerConnection>  </scm>  <dependencies>    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>      <version>3.8.1</version>      <scope>test</scope>    </dependency>  </dependencies></project>


  然后在pom下添加这段插件
<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-gpg-plugin</artifactId>    <version>1.4</version>    <executions>        <execution>    <id>sign-artifacts</id>    <phase>verify</phase>    <goals>        <goal>sign</goal>    </goals></execution>    </executions></plugin>


  首先运行这个命令,然后按照提示输入你的gpg密码,这一步实际上已经将你的jar包和pom文件都签名了。
mvn clean install


  然后运行这个命令
mvn javadoc:jar source:jar repository:bundle-create


  如果遇到javadoc中文字符编码问题,请在后面加上 -Dencoding=utf-8 参数再运行该命令就没问题了  然后进入到target目录  然后执行这个命令,分别把javadoc.jar 和 sources.jar 打上自己的签名
gpg -ab xxx-javadoc.jar

  输入密码,然后接着运行下面这个命令
gpg -ab xxx-sources.jar

  输入密码
  生成了.asc的文件,用压缩工具打开xxx-bundle.jar文件,然后将刚刚生成的那两个.asc文件(javadoc和sources的)复制到压缩包里面。
最后将这个bundle上传到sonatype-oss上即可。若检查通过,直接状态就是closed的了,别忘了选中后release哦。

热点排行