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,如原文所說


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM