maven入門 (二)_私服安裝與上傳下載


本篇文章主要介紹maven的私服安裝和 jar包的上傳與下載。畢竟大家還是在公司需要上傳jar包到自己公司私服的。

1.安裝私服

下載鏈接: https://pan.baidu.com/s/17dbQny3d1VgKBA529BTwJA 密碼: uizp
下載完成。(我的win系統),解壓文件

enter image description here

通過系統管理員身份運行cmd,進入nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin目錄,運行 nexus install

enter image description here

啟動私服,運行 nexus start

enter image description here

訪問網址:http://localhost:8081/nexus/#welcome 登錄私服:admin/admin123

enter image description here
enter image description here

倉庫類型

enter image description here

2.上傳

修改maven配置文件
  • 找到你的maven 安裝路徑如:E:\app\apache-maven-3.5.3\conf
  • 修改setting.xml 文件,放在servers 節點下
 	<server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
	<server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
修改項目 pom文件
    <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>
執行deploy命令發布到私服

這里我使用idea 進行發布,最近在使用idea 進行開發,感覺不錯

  • 點擊"Edit Configurations"
    enter image description here
  • 進入Run/Debug Configurations窗口,點擊左上角的"+",在彈出的"Add New Configuration"列表中選擇"maven".
    enter image description here
  • 為新的configuration輸入名稱和執行的命令,點擊確認
    enter image description here
  • 配置完成后,新的configuration會成為默認的configuration,直接點擊運行按鈕--三角形綠色按鈕
    http://p7zk4x9pv.bkt.clouddn.com//mavenTIM%E6%88%AA%E5%9B%BE20180519084006.png
  • 執行配置的maven命令
    enter image description here
  • 驗證上傳成功
    enter image description here

3.下載

修改maven配置文件 setting.xml
  • 配置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> 
  • 配置activeProfiles
  <activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>
查看下載maven語句

enter image description here

        <dependency>
            <groupId>com.example</groupId>
            <artifactId>springbootdemo</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
將上面的代碼粘貼到項目pom.xml 中,idea會右下角提示你import changes,點擊

enter image description here

驗證下載成功

找到你的本地maven倉庫
http://p7zk4x9pv.bkt.clouddn.com/TIM%E6%88%AA%E5%9B%BE20180519085709.png

總結

好了,現在 終於學會上傳私服jar包了。我的maven學習 ,就暫時告一段落了。玩的開心


免責聲明!

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



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