Nexus私服配置
二、 Nexus安裝與啓動
1、 解壓
2、 配置jdk環境變量(如果java的環境變量之前沒有配置的)
在解壓後nexus-2.14.5-02文件\bin\jsw\conf 裏的wrapper.conf配置
3、 dos啓動私服 nexus
繼續後輸入nexusinstall 服務裏安裝了nexus
第一種可以在服務內啓動
第二種dos輸入nexus start啓動
4、 訪問私服默認端口:8081
瀏覽器輸入localhost:8081/nexus進入私服
Log In 登入
默認 用戶名:admin 密碼:admin123
二、 將項目發佈到私服
1、 配置
第一步: 需要在客戶端即部署 dao 工程的電腦上配置maven 環境,並修改 settings.xml 文件,配置連接私服的用戶和密碼。
此用戶名和密碼用於私服校驗,因爲私服需要知道上傳都 的賬號和密碼 是否和私服中的賬號和密碼 一致。
<server> <id>releases</id> <username>deployment</username> <password> deployment123</password> </server> <server> <id>snapshots</id> <username> deployment </username> <password> deployment123</password> </server>
|
如果之前setting設置連接的aliyun倉庫刪掉
releases 連接發佈版本項目倉庫
snapshots連接測試版本項目倉庫
第二步: 配置父模塊項目 pom.xml
配置私服倉庫的地址,本公司的自己的 jar包會上傳到私服的宿主倉庫,根據工程的版本號決定上傳到哪個宿主倉庫,如果版本爲 release 則上傳到私服的 release 倉庫,如果版本爲 snapshot 則上傳到私服的 snapshot 倉庫
<distributionManagement> <repository> <id>releases</id> <url>http://localhost:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement> |
注意:pom.xml 這裏<id> 和 settings.xml 配置 <id> 對應!
第三步:將項目工程打成 jar 包發佈到私服:
1、首先啓動 nexus
2、對工程執行 deploy命令
根據本項目pom.xml中version定義決定發佈到哪個倉庫,如果version定義爲snapshot,執行 deploy 後查看 nexus 的 snapshot 倉庫,如果 version 定義爲 release 則項目將發佈到 nexus的 release 倉庫
三、 從私服下載 jar 包
第一步:管理倉庫組
nexus中包括很多倉庫,hosted中存放的是企業自己發佈的jar包及第三方公司的jar包,proxy 中存放的是中央倉庫的jar,爲了方便從私服下載 jar 包可以將多個倉庫組成一個倉庫組,每個工程需要連接私服的倉庫組下載 jar 包。打開 nexus 配置倉庫組,如下圖:
上圖中倉庫組包括了本地倉庫、代理倉庫等。
第二步:在 setting.xml 中配置倉庫
在客戶端的 setting.xml 中配置私服的倉庫,由於 setting.xml 中沒有 repositories 的配置標籤需要使用 profile 定義倉庫。
<profile> <!--profile 的 id-->
<id>dev</id> <repositories> <repository> <!--倉庫 id,repositories 可以配置多個倉庫,保證 id 不重複--> <id>nexus</id> <!--倉庫地址,即 nexus 倉庫組的地址--> <url>http://localhost:8081/nexus/content/groups/public/</url> <!--是否下載 releases 構件--> <releases> <enabled>true</enabled> </releases> <!--是否下載 snapshots 構件--> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <!-- 插件倉庫,maven 的運行依賴插件,也需要從私服下載插件 --> <pluginRepository> <!-- 插件倉庫的 id 不允許重複,如果重複後邊配置會覆蓋前邊 --> <id>public</id> <name>Public Repositories</name> <url>http://localhost:8081/nexus/content/groups/public/</url> </pluginRepository> </pluginRepositories> </profile> |
使用 profile 定義倉庫需要激活纔可生效。
<activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles> |
第二步:在 web子模塊下的pom.xml 中配置
<repositories> <repository> <releases> <enabled>true</enabled>
</releases> <snapshots> <enabled>true</enabled> </snapshots> <id>public</id> <name>Public Repositories</name> <url>http://localhost:8081/nexus/content/groups/public/</url> </repository> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>public</id> <name>Public Repositories</name> <url>http://localhost:8081/nexus/content/groups/public/</url> </pluginRepository> <pluginRepository> <releases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> </pluginRepository> </pluginRepositories> |
四、 私服索引維護
輔助材料indexer文件夾
打開文件夾裏的jar.txt
Jar打開內容
將jar裏內容複製到dos系統
將解壓好的內容放入E:\sonatype-work\nexus\indexer\central-ctx