nexus3添加第三方jar

  最近在看maven的打包及管理,然後就看到nexus,自己在安裝的時候就下載了最新版的nexus-3.2.0-01-win64,按照文档部署后启动,浏览。之前一致使用的是2.0的,所以还是需要导出点点,熟悉一下功能。

  熟悉2.0的都知道,那是可以上传自己的jar到库中,方便引用,但是3.0中,没有操作界面来上传jar,查阅3.0的文档,之找到一个上传Raw文件的方式,如下:

16.5 Uploading Files to Hosted Raw Repositories

Many other tools, besides using Maven, can be used to upload files to a hosted raw repository. A simple HTTP PUT can upload files. The following example uses the curl command and the default credentials of the admin user to upload a test.png file to a hosted raw repository with the name documentation.

An Example Upload Command Using curl:

curl -v --user ’admin:admin123’ --upload-file ./test.png http://localhost:8081/repository/documentation/test.png

After a completed upload the repository manager provides the file at the URL http://localhost:8081/repository/documentation/test.png. Using this approach in a script entire static websites or any other binary resources can be uploaded.

  这段描述的是上传一个文件,如图片、html、js、css等等,上传到指定路径后,就可以通过url访问改资源。例如上传一个jQuery库文件,引用时只需添加url指向这个资源,而不需要在本地工程添加库文件,也可多个项目共享等等。

但是,这个明显不是我想要的,继续寻找,最后在stackoverflow上面找到了答案:

当nexus3为HTTP时,使用如下方式:

如你需要上传utils-1.0.jar包,首先需准备新建一个pom.xml文件,内容如下:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.foo</groupId>
  <artifactId>utils</artifactId>
  <version>1</version>
</project>

pom.xml和utils-1.0.jar两个文件放到一块就行,接下来使用命令上传到nexus上面:

curl -v -u admin:admin123 --upload-file pom.xml http://localhost:8081/nexus/repository/maven-releases/org/foo/utils/1.0/utils-1.0.pom

上传pom.xml文件到nexus上,并改名为utils-1.0.pom,注意你的release路径和包放的路径

curl -v -u admin:admin123 --upload-file utils-1.0.jar http://localhost:8081/nexus/repository/maven-releases/org/foo/utils/1.0/utils-1.0.jar

上传jar到相同路径下面。

  此时,utils-1.0.jar可以在maven工程的pom中使用了,我使用log4j-1.2.12.jar测试,这种方式可以。

对于nexus设置为HTTPS的上传方法,我没测试,使用https的花需要配置的密匙文件,请看原文:http://stackoverflow.com/questions/38593513/how-to-upload-jar-to-nexus-oss-3

 我是在window10下面,使用的时Window Subsystem for Linux,在里面使用的curl上传的,也可自己下载curl.exe,如原文所说

posted @ 2017-01-08 19:38  风雨咒之无上密籍  阅读(5880)  评论(0编辑  收藏  举报