07 Maven高级:02.私服的应用

15私服的安装和启动、16私服的应用、17安装第三方jar包到本地仓库、18安装第三方jar包到私服

 

15私服的安装和启动

nexus私服

 

16私服的应用

4. 将项目发布到私服

4.2 配置
第一步: 需要在客户端即部署 ssm_dao 工程的电脑上配置 maven环境,并修改 settings.xml
文件, 配置连接私服的用户和密码 。

<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>

第二步: 配置项目 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> 对应!

 4.3 测试
将项目 dao 工程打成 jar 包发布到私服:
1、 首先启动 nexus
2、 对 ssm_dao 工程执行 deploy 命令


5. 从私服下载 jar 包

5.3 在 setting.xml 中配置仓库
在客户端的 setting.xml 中配置私服的仓库,由于 setting.xml 中没有 repositories 的配置标签,需要使用 profile 定义仓库。

	<!-- 下载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>

使用 profile 定义仓库需要激活才可生效。

	<activeProfiles>
		<activeProfile>dev</activeProfile>
	</activeProfiles>

配置成功后通过 eclipse 查看有效 pom,有效 pom 是 maven 软件最终使用的 pom 内容,程
序员不直接编辑有效 pom。

17安装第三方jar包到本地仓库

--安装第三方jar包到本地仓库

----进入jar包所在目录运行
mvn install:install-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dfile=fastjson-1.1.37.jar -Dpackaging=jar
----打开cmd直接运行
mvn install:install-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=C:\my_java\授课资料\资料:maven【高级】\安装第三方jar包\fastjson-1.1.37.jar

  如果之前配置过maven的环境变量,通过命令 mvn -version 可以成功查看版本就可以在cmd窗口中使用下面的安装POM命令。

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.1.0 -Dpackaging=jar -Dfile=F:\ojdbc14-10.2.0.1.0.jar

18安装第三方jar包到私服

--安装第三方jar包到私服

--在settings配置文件中添加登录私服第三方登录信息
<server>
<id>thirdparty</id>
<username>admin</username>
<password>admin123</password>
</server>
----进入jar包所在目录运行
mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=fastjson-1.1.37.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty
----打开cmd直接运行
mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=C:\my_java\授课资料\资料:maven【高级】\安装第三方jar包\fastjson-1.1.37.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty

=================

end 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

康冕峰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值