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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章