使用maven工具如何往私服中上傳和下載專案
阿新 • • 發佈:2020-12-24
1. 如何將編寫好的專案上傳到私服
首先要在 maven-->conf--> settings.xml中配置私服的相關資訊:
<servers>
<!--配置遠端倉庫(私服)--> <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server>
</servers>
然後在將要上傳的maven專案中的pom.xml檔案中新增如下配置,其中 ip 地址是私服伺服器的 ip
<distributionManagement>
<repository>
<id>releases</ id>
<url>http://192.168.132.125:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://192.168.132.125:8081/nexus/content/repositories/snapshots/</url>
</ snapshotRepository>
</distributionManagement>
最後需要在maven專案中使用desploy命令,進行專案部署即可。專案就會上傳到私服。
2. 如何從私服中下載專案
首先需要在 maven-->conf--> settings.xml中配置私服的相關配置
<profiles>
<!-- 從私服下載jar包配置 -->
<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>
</profiles>
<!-- 從私服下載jar包配置進行啟用 -->
<activeProfiles>
<!--activeProfile的值是配置profile標籤的id -->
<activeProfile>dev</activeProfile>
</activeProfiles>
備註:從私服中下載專案和 jar 的配置是一樣的。
在開發專案的pom.xml中指定將要在私服中下載的專案的座標。當開發專案執行時,從本地倉庫找不到依賴的專案,會自動從私服中下載,並新增到本地倉庫。
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>maven_day02_dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>