Linux下使用nexus搭建maven倉庫私服

有個maven私服能夠很方便地管理咱們的jar包和發佈構建到遠程倉庫,本文就介紹瞭如何在linux下一步步使用nexus搭建maven私服java

原文連接:linux

    http://www.tuicool.com/articles/E7ZBv2 apache


下載安裝

最新nexus下載地址: http://www.sonatype.org/nexus/gowindows

解壓後會在同級目錄中,出現兩個文件夾: nexus-2.11.4-01 和sonatype-work ,前者包含了nexus的運行環境和應用程序,後者包含了你本身的配置和數據。網絡

解壓命令:unzip nexus-2.11.4-01-bundle.zipapp

啓動nexus

# cd nexus-2.11.4-01/bin/
# ls
jsw  nexus  nexus.bat
# ./nexus
Usage: ./nexus { console | start | stop | restart | status | dump }
# ./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.


查看控制檯:less

# ./nexus console
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Running Nexus OSS...
wrapper  | --> Wrapper Started as Console
wrapper  | Launching a JVM...
wrapper  | JVM exited while loading the application.
jvm 1    | wrapper  | Unable to start JVM: No such file or directory (2)
wrapper  | Reloading Wrapper configuration...
wrapper  | Launching a JVM...
wrapper  | JVM exited while loading the application.
jvm 2    | wrapper  | Unable to start JVM: No such file or directory (2)
wrapper  | Reloading Wrapper configuration...
wrapper  | Launching a JVM...
wrapper  | JVM exited while loading the application.
jvm 3    | wrapper  | Unable to start JVM: No such file or directory (2)
wrapper  | Reloading Wrapper configuration...
wrapper  | Launching a JVM...
wrapper  | JVM exited while loading the application.
jvm 4    | wrapper  | Unable to start JVM: No such file or directory (2)
wrapper  | Reloading Wrapper configuration...
wrapper  | Launching a JVM...
wrapper  | JVM exited while loading the application.
jvm 5    | wrapper  | Unable to start JVM: No such file or directory (2)
wrapper  | There were 5 failed launches in a row, each lasting less than 300 seconds.  Giving up.
wrapper  |   There may be a configuration problem: please check the logs.
wrapper  | <-- Wrapper Stopped

啓動失敗,緣由:未安裝JDK
eclipse

安裝JDK後,查看控制檯:jvm

# ./nexus console
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Running Nexus OSS...
Nexus OSS is already running.


控制檯顯示啓動成功。maven

查看nexus日誌:

# cd ../logs/
# ls -l
total 48
-rw-r--r-- 1 root root 43311 2015-09-16 19:46 wrapper.log
# tail -f wrapper.log


配置nexus

訪問網址: http://yourhostname:8081/nexus


右上角以admin登錄,默認用戶名/密碼:admin/admin123。

3rd party、Snapshots、Releases這三個,分別用來保存第三方jar、項目組內部的快照、項目組內部的發佈版.

手動添加第三方jar

將第三方的jar上傳到nexus上面:

點擊Upload Artifact(s)按鈕提交後即上傳。

查看上傳的jar包以下:

在項目中使用私服的jar包配置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>com.vclk.mkt.crawler</groupId>  <artifactId>MarketingCrawler</artifactId>  <packaging>jar</packaging>  <version>0.3</version>  <name>MarketingCrawler</name>  <url>http://maven.apache.org</url>  <!-- 倉庫地址 -->  <repositories>      <repository>          <id>nexus</id>          <name>Team Nexus Repository</name>          <url>http://yourhostname:8081/nexus/content/groups/public</url>      </repository>  </repositories>    <!-- 插件地址 -->  <pluginRepositories>      <pluginRepository>          <id>nexus</id>          <name>Team Nexus Repository</name>          <url>http://yourhostname:8081/nexus/content/groups/public</url>      </pluginRepository>  </pluginRepositories>  <!-- jar -->  <dependencies>      <dependency>          <groupId>de.innosystec</groupId>          <artifactId>java-unrar</artifactId>          <version>0.5</version>      </dependency>  </dependencies></project>

Maven在項目根目錄下執行mvn eclipse:eclipse命令時,所依賴的jar包都會從私服中下載到本地並關聯上項目,私服中沒有就會從網絡上下載到私服,本地再從私服下載。

自動發佈構件到遠程倉庫

在工程的pom.xml中添加:

<distributionManagement>  <repository>      <id>nexus-releases</id>      <url>http://yourhostname:8081/nexus/content/repositories/releases/</url>  </repository>  <snapshotRepository>      <id>nexus-snapshots</id>      <url>http://yourhostname:8081/nexus/content/repositories/snapshots/</url>  </snapshotRepository></distributionManagement>


進入maven的安裝目錄apache-maven-3.1.1\conf目錄下,向settings.xml配置文件中的 語句塊中添加以下所示:

<servers>  <server>      <id>nexus-releases</id>      <username>admin</username>      <password>admin123</password>  </server>  <server>      <id>nexus-snapshots</id>      <username>admin</username>      <password>admin123</password>  </server></servers>


進入windows命令行,在工程所在目錄下執行

mvn deploy

所部署的包就自動上傳到了nexus安裝目錄下的 /maven/nexus/sonatype-work/nexus/storage/releases/com/vclk/mkt/crawler/MarketingCrawler/0.3 目錄

nexus倉庫中各目錄介紹

項目中的各類jar包和項目快照等都放在 /nexus/sonatype-work/nexus/storage/ 目錄下,在這個目錄下包括如下各類目錄和存放相應文件。

/nexus/sonatype-work/nexus/storage/central - 用於放置maven從中央倉庫中下載下來的項目pom.xml中配置到的相關jar包;

/nexus/sonatype-work/nexus/storage/thirdparty - 用於放置本身手動上傳的第三方jar包;

/nexus/sonatype-work/nexus/storage/releases - 用於放置項目deploy後的發佈版。

相關文章
相關標籤/搜索