maven深入學習筆記_007配置從私服拉取jar以及上傳jar到私服

一、配置從私服拉取jar

    打開maven的setting文件,配置如下

	<!-- 強制讓jar包下載走私服 -->
	<mirrors>
	    <mirror>
			<id>nexus</id>
			<mirrorOf>*</mirrorOf>
			<url>http://localhost:8081/repository/maven-public/</url>
		</mirror>
  	</mirrors>

	<profiles>
		<profile>
			<!-- 對應activeProfiles-activeProfile的內容 -->
			<id>nexus</id>
			<!-- 倉庫地址 -->
			<repositories>
				<repository>
					<!-- 私服id,覆蓋maven-model模塊下的父id,讓maven不走中央倉庫下載,走私服下載 -->
					<id>central</id>
					<!-- 名字 -->
					<name>Nexus</name>
					<!-- 私服地址,寫central後,會去mirror裏面找 -->
					<url>http://central</url>
					<!-- 支持releases版本 -->
					<releases>
						<enabled>true</enabled>
					</releases>
					<!-- 支持snapshots版本 -->
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<!-- 插件地址 -->
			<pluginRepositories>
				<pluginRepository>
					<id>central</id>
					<name>Nexus Plugin Repository</name>
					<url>http://central</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>
	
	<!-- 選擇使用的profile -->
	<activeProfiles>
		<activeProfile>nexus</activeProfile>
	</activeProfiles>

二、配置項目上傳到私服

    在pom.xml裏新增如下配置。

	<distributionManagement>
		<!-- releases倉庫 -->
		<repository> 
			<!-- id,對應maven的setting.xml裏面server配置的id -->
			<id>nexus-releases</id>
			<!-- 自定義的名字 -->
			<name>Nexus Release Repository</name>
			<!-- releases倉庫url -->
			<url>http://localhost:8081/repository/maven-releases/</url>
		</repository>
		<!-- snapshots倉庫 -->
		<snapshotRepository>
			<!-- id,對應maven的setting.xml裏面server配置的id -->
			<id>nexus-snapshots</id>
			<!-- 自定義的名字 -->
			<name>Nexus Snapshot Repository</name>
			<!-- snapshots倉庫url -->
			<url>http://localhost:8081/repository/maven-snapshots/</url>
		</snapshotRepository>
	</distributionManagement>
	
	<!-- 編譯打包插件 -->
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
					<encoding>${project.build.sourceEncoding}</encoding>
				</configuration>
			</plugin>
		</plugins>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
			</resource>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.xml</include>
				</includes>
			</resource>
		</resources>
	</build>

    打開maven的setting文件,配置如下

	<!-- 登錄遠程倉庫的用戶名和命令 -->
	<servers>
		<server>
			<!-- id,對應項目裏面pom.xml裏面distributionManagement配置的id -->
			<id>nexus-releases</id>
			<!-- 登錄nexus的用戶名 -->
			<username>xxx</username>
			<!-- 登錄nexus的密碼 -->
			<password>xxx</password>
		</server>
		<server>
			<!-- id,對應項目裏面pom.xml裏面distributionManagement配置的id -->
			<id>nexus-snapshots</id>
			<!-- 登錄nexus的用戶名 -->
			<username>xxx</username>
			<!-- 登錄nexus的密碼 -->
			<password>xxx</password>
		</server>
	</servers>

    執行 mvn clean deploy 就可以把項目打包上傳到私服。

三、第三方jar上傳到私服

    執行命令:mvn deploy:deploy-file -DgroupId=com.xxx.xxx.xxx -DartifactId=xxx-xxx -Dversion=1.0 -Dpackaging=jar -Dfile=D:\xxx-1.0.jar -Durl=http://localhost:8081/repository/maven-Third-party/ -DrepositoryId=maven-Third-party

  1. deploy:deploy-file:上傳jar命令
  2. -DgroupId:groupId
  3. -DartifactId:artifactId
  4. -Dversion:版本
  5. -Dpackaging:項目類型
  6. -Dfile:jar包路徑
  7. -Durl:倉庫地址
  8. -DrepositoryId:倉庫id
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章