maven入门 (二)_私服安装与上传下载

本篇文章主要介绍maven的私服安装和 jar包的上传与下载。毕竟大家还是在公司需要上传jar包到自己公司私服的。

1.安装私服

下载链接: https://pan.baidu.com/s/17dbQny3d1VgKBA529BTwJA 密码: uizp
下载完成。(我的win系统),解压文件

enter image description here

通过系统管理员身份运行cmd,进入nexus-2.12.0-01-bundle exus-2.12.0-01in目录,运行 nexus install

enter image description here

启动私服,运行 nexus start

enter image description here

访问网址:http://localhost:8081/nexus/#welcome 登录私服:admin/admin123

enter image description here
enter image description here

仓库类型

enter image description here

2.上传

修改maven配置文件
  • 找到你的maven 安装路径如:E:appapache-maven-3.5.3conf
  • 修改setting.xml 文件,放在servers 节点下
 	<server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
	<server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
修改项目 pom文件
    <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命令发布到私服

这里我使用idea 进行发布,最近在使用idea 进行开发,感觉不错

  • 点击"Edit Configurations"
    enter image description here
  • 进入Run/Debug Configurations窗口,点击左上角的"+",在弹出的"Add New Configuration"列表中选择"maven".
    enter image description here
  • 为新的configuration输入名称和执行的命令,点击确认
    enter image description here
  • 配置完成后,新的configuration会成为默认的configuration,直接点击运行按钮--三角形绿色按钮
    http://p7zk4x9pv.bkt.clouddn.com//mavenTIM%E6%88%AA%E5%9B%BE20180519084006.png
  • 执行配置的maven命令
    enter image description here
  • 验证上传成功
    enter image description here

3.下载

修改maven配置文件 setting.xml
  • 配置profile
		<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> 
  • 配置activeProfiles
  <activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>
查看下载maven语句

enter image description here

        <dependency>
            <groupId>com.example</groupId>
            <artifactId>springbootdemo</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
将上面的代码粘贴到项目pom.xml 中,idea会右下角提示你import changes,点击

enter image description here

验证下载成功

找到你的本地maven仓库
http://p7zk4x9pv.bkt.clouddn.com/TIM%E6%88%AA%E5%9B%BE20180519085709.png

总结

好了,现在 终于学会上传私服jar包了。我的maven学习 ,就暂时告一段落了。玩的开心

原文地址:https://www.cnblogs.com/zhenghengbin/p/9059223.html