私服

私服

​ 正式开发时,不同的项目组开发不同的工程。dao工程开发完毕,发布到私服。service从私服下载dao。

​ 公司在自己的局域网内搭建自己的远程仓库服务器,称为私服,私服服务器即是公司内部的maven远程仓库,每个员工的电脑上安装maven软件并且连接私服服务器,员工将自己开发的项目打成jar并发布到私服服务器,其它项目组从私服服务器下载所依赖的构件(jar)。

在这里插入图片描述

搭建私服环境
1下载nexus

Nexus 是Maven仓库管理器,通过nexus可以搭建maven仓库,同时nexus还提供强大的仓库管理功能,构件搜索功能等。下载地址:http://www.sonatype.org/nexus/archived/

2 安装nexus
cmd进入bin目录,执行nexus.bat install
3 卸载nexus
cmd进入nexus的bin目录,执行:nexus.bat uninstall
4 启动nexus
方法1:
	cmd进入bin目录,执行nexus.bat start
方法2:
	windows服务中直接启动nexus服务

如何验证启动成功:查看nexus的配置文件conf/nexus.properties

# Jetty section
application-port=8081  	# nexus的访问端口配置
application-host=0.0.0.0 	# nexus主机监听配置(不用修改)
nexus-webapp=${bundleBasedir}/nexus 	# nexus工程目录
nexus-webapp-context-path=/nexus	 # nexus的web访问路径

# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus   # nexus仓库目录
runtime=${bundleBasedir}/nexus/WEB-INF  # nexus运行程序目录

访问:
http://localhost:8081/nexus/

使用Nexus 内置账户admin/admin123登陆:
点击右上角的Log in,输入账号和密码 登陆
私服仓库类型

nexus的仓库:

在这里插入图片描述

nexus的仓库有4种类型:

1.	hosted,宿主仓库,部署自己的jar到这个类型的仓库,包括releases和snapshot两部分,Releases公司内部发布版本仓库、 Snapshots 公司内部测试版本仓库
2.	proxy,代理仓库,用于代理远程的公共仓库,如maven中央仓库,用户连接私服,私服自动去中央仓库下载jar包或者插件。 
3.	group,仓库组,用来合并多个hosted/proxy仓库,通常我们配置自己的maven连接仓库组。
4.	virtual(虚拟):兼容Maven1 版本的jar或者插件 
nexus仓库默认在sonatype-work目录中:
将项目发布到私服
1. 把dao模块上传到私服(如果上述setting.xml文件中配置过再次检查是否配置完整正确):
    第一步:配置私服地址 
            1. 在settings.xml添加:
          <server>
                <id>releases</id>
                <username>admin</username>
                <password>admin123</password>
          </server>
          <server>
                <id>snapshots</id>
                <username>admin</username>
                <password>admin123</password>
          </server>
		2.在当前项目的pom.xml文件添加:
		  <!-- 配置远程发布到私服,mvn deploy -->
              <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命令,不同开发工具会有差异。
    
    如果所有配置正确,发现上传私服失败,需要进入私服找到指定仓库 
         Repository--- Access Settings--Deployment Policy修改为允许发布
从私服下载jar包
service模块从私服下载dao包
        在settings.xml文件中
       <profile>
        <id>dev</id>
        <repositories>
            <repository>
                <id>nexus</id>
                <name>nexus</name>
                <url>http://localhost:8081/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <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>
    2.激活私服
		<!-- 激活 -->
<activeProfiles>
  <activeProfile>dev</activeProfile>
</activeProfiles>
          
注意:
    私服一般安装在内网的其他服务器上,而不是本机上。因此上面的配置中localhost的部分在实际情况中应该修改为公司中内网的私服服务器地址。
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值