[精讚] [會員登入]
227

【Nexus Repository Manager】(deploy)使他人可以對遠端資料庫做讀寫

使用 Nexus Repository Manager 來讓各個工程師控制自己的 Jar 包,不會有 Github Merge Crashed 問題。

分享此文連結 //n.sfs.tw/16119

分享連結 【Nexus Repository Manager】(deploy)使他人可以對遠端資料庫做讀寫@小編過路君子
(文章歡迎轉載,務必尊重版權註明連結來源)
2023-03-20 19:37:11 最後編修
2023-03-20 17:42:09 By 過路君子
 

大家好,這裡是正在讀寫資料庫的小編過路君子

好不容易架好了資料庫,那第一件事情當然是......對!上來發個文

 

 

Nexus Repository Manager 的安裝在網路上各處已經有許許多多的人對此著墨了。

所以小編在此不提及如何安裝,僅筆記如何設定權限讓他人「」可以將寫好的 jar 包上傳至資料庫。

順帶一提,小編所架設的 Maven Repository 是全世界都能連線,但是必須要擁有帳號和密碼才能對其做存取,所以相對的會附上完整的 setting.xml 和 pom.xml 供各位參考。

 

首先,我們先連線到 Nexus Repository Manager 的管理頁面並登入 admin 的帳號。

(所有圖片點擊都可以放大、變高清)

在新增角色的時候我們僅需簡單設置兩個屬性:名稱和權限。

名稱相對好理解,就依照各自的喜好或是習慣叫就好。

 

而我們總共需要新增的權限為以下四個:

nx-repository-view-*-*-add
nx-repository-view-*-*-edit
nx-repository-view-*-*-read
nx-repository-view-*-*-browse

其中的 nx-repository-view-*-*-browse 可有可無。

如果沒有給予,仍就可以透過 Maven 來部署(deploy)我們的 jar 包到遠端資料庫,只是就不能透過瀏覽器直接連線到資料庫內查看目前有哪些 jar 包可用。

 

如果細心點的人就會發現,基本上唯獨 nx-repository-view-*-*-delete 的權限之外小編都給了。

如果此權限不給的話就只能上傳 jar 包而已,無法對已經上傳的 jar 包進行刪除,各位可以依照自己目前所需斟酌給予。

 

我們的資料庫預設會阻擋重複上傳的 jar 包,所謂的重複上傳就是 groupId 和 artifactId 還有 version 所對應的路徑已經有檔案的存在了。

所以使用者如果沒有刪除的權限,那不小心上傳錯 jar 包是無法刪除重傳或是強制覆蓋的,只能將版本號改動並再次上傳了。

如果想要允許使用者能覆蓋已經存在的檔案,可以透過下列的方式來修改:

進入將頁面往下滾動,找到 Hosted → Deployment policy 選擇「Allow redeploy」即可。

 

然後將此角色給予我們現有的使用者即可:

同樣往下滑,找到 Roles 區塊,將剛剛創建的身分組從左邊移動到右邊。

這樣,這位使用者就可以對我們的 Maven Repository 進行 jar 檔的部署囉!

 

接下來小編就在這快速地丟出 setting.xml 和 pom.xml 這兩個檔案。

<!-- setting.xml -->

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">;
  <localRepository>/usr/share/maven/ref/repository</localRepository>

  <servers>
    <server>
      <id>maven-public</id>
      <username>username</username>
      <password>password</password>
    </server>

    <server>
      <id>maven-releases</id>
      <username>username</username>
      <password>password</password>
    </server>

    <server>
      <id>maven-snapshots</id>
      <username>username</username>
      <password>password</password>
    </server>
  </servers>

  <mirrors>
    <mirror>
      <id>maven-public</id>
      <name>maven-public</name>

      <url>http://127.0.0.1:8080/repository/maven-public/</url>
      <mirrorOf>*</mirrorOf>
      <updatePolicy>always</updatePolicy>
    </mirror>
  </mirrors>
</settings>

小編在設定 mirrors 上吃了很大的悶虧,因為目前網路上常見的版本都僅有設置 maven-releases 庫和 maven-snapshots 庫的登入資訊。

反而對於我們要拉檔案的 maven-public 庫沒有設置任何的資訊,所以一旦執行就會吃到以下的錯誤:

Transfer failed for http://127.0.0.1:8080/repository/maven-releases/jar/execute/file/1.0.0/test-1.0.0.jar 401 Unauthorized

 

接下來就是 pom.xml 的設定了:

<!-- pom.xml -->

<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.0 http://maven.apache.org/maven-v4_0_0.xsd">;
    <modelVersion>4.0.0</modelVersion>

    <groupId>please.fix.here</groupId>
    <artifactId>yourRepo</artifactId>
    <version>0.0.0</version>

    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <distributionManagement>
        <repository>
            <id>maven-releases</id>
            <name>User Porject Release</name>
            <url>http://127.0.0.1:8080/repository/maven-releases/</url>
        </repository>

        <snapshotRepository>
            <id>maven-snapshots</id>
            <name>User Porject Snapshot</name>
            <url>http://127.0.0.1:8080/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

    <repositories>
        <repository>
            <id>maven-public</id>
            <name>Nexus Repository</name>
            <url>http://127.0.0.1:8080/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <dependencies>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/java/</directory>
                <filtering>false</filtering>
                <includes>
                    <include>**</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.3.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.7.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                    <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

話說,其實資料庫的連線網址 Nexus Repository Manager 都已經有幫我們寫出來了。

 

 

 

後記

安裝好之後小編有試著 deploy 一個 jar 包到那個資料庫裡面,然後再跑去開一台乾淨的電腦,照著上面的那兩個檔案再次設定一次。

在經過一番琢磨 import 資訊該如何打之後,總算成功將位於小編私架的 Maven Repository 上的 jar 包執行起來啦!

END

你可能感興趣的文章

【C++】一些好用的C++小功能 —— 貳 承襲上一篇的C++小功能,筆記下來以免自己以後忘記了。

【SeaChest & Synology】512e(Advanced Format / AF) 轉換至 4Kn 好不容易入手了一顆硬碟,但是卻無法使用,除了賣掉還有更好的方法嗎?

【Docker hub】[Linux]以IPv6來pull容器(container)吧! 在一個 IPv6 還不盛行的年代,做事情總是特別麻煩

【Wicket】[Cookie]如何讀取和設定客戶端的Cookie 對於某些參數需要給予使用者,我們可以使用 Cookie 來讓客戶端記著,之後再跟伺服器裡的比對來達到驗證的目的

【Firefox \ Maven】[Headless](Linux) 如何使用Maven打包並驅動Firefox 有時候我們需要取得渲染後的網頁,當然是直接呼叫瀏覽器出來用啦

【Stable Diffusion web UI】[AI 作畫](Linux)無 NVIDIA 顯卡之伺服器運行測試 凡事就是要試試看,才知道最後的結果

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

希萌創意預計在今年7月繼東津萌米之後再次推出新遊戲--食用性少女! 今天來介紹希萌創意的心企劃案,來讓大家知道這個消息!讓大家的錢包君一起來減肥吧!Ψ(☆w☆)

【分享、整合串】什麼?!高捷少女竟然有二創小說!! 由時零宇宙大大在巴哈上面連載的二創高捷少女小說,就讓我們來看看,究竟在時零大大的巧手下,高捷少女們會擦出什麼樣的火花吧!

高捷少女:小穹與果仁巧克力㊤ 阿敏突然輕笑一聲,從櫃臺拿來一個塑膠餐盒,打開給大家看。「這是小穹烤的餅乾,妳們吃吃看就知道她為什麼不想講了。」小穹變得緊張起來。「阿敏,妳怎麼還留著呀?」艾米莉亞、婕兒與耐耐各自拿了一塊,把夾著奶油

高捷少女:地下城的探險少女① 婕兒心中一奇,便走上前看著仔細。那塊凹進去的地方中心大約三公分厚,越往邊緣就越淺,圓型直徑十五公分。婕兒拿出銅盤對比一下,發現兩者大小竟然一致,銅盤似乎能夠完整的嵌進去。     婕兒看著凹槽,心中

高捷少女:地下城的探險少女③ 過了十分鐘後,前方的天花板滴下一滴水珠,發出「噠」一聲響亮地落在石地上,讓大家嚇一跳。     「什麼嘛,只是水珠而已。」艾米撫著胸口噓了一聲。     忽然間,耐耐的臉色發白起來。「各位,你們看