学习笔记【Maven高级】

基础知识回顾

maven是一个项目管理工具

依赖管理:
maven对项目中jar包的管理过程。传统工程我们直接把jar包放置在项目中。
maven工程真正的jar包放置在仓库中,项目中只用放置jar包的坐标。

一键构建:
maven自身继承了tomcat插件,可以对项目进行编译,测试,打包,安装,发布等操作。

仓库种类:
本地仓库,远程仓库(私服),中央仓库

maven常用命令:
clean,compile,test,package,install,deploy。

maven生命周期:
清理生命周期,默认生命周期,站点生命周期

jar包的依赖冲突

解决方式一:

第一声明优先原则:哪个jar包的坐标在靠上的位置,这个jar包就先声明,先声明的jar包坐标下的依赖包,可以优先进入项目中。

maven导入jar包中的一些概念:

  • 直接依赖:项目中直接导入的jar包,就是该项目的直接依赖包
  • 传递依赖:项目中没有直接导入的jar包,可以通过项目直接以来jar包传递到项目中去。
解决方式二:

路径近者优先原则。直接依赖路径笔传递路径近,那么最终项目进入的jar包是路径近的直接依赖包。

解决方式三:

当我们要排除某个jar包下依赖包,可以使用exclusions标签,在配置exclusions标签的时候,内部不写版本号。

常用标签的作用

  • dependencyManagement 作用jar包版本
  • properties 管理jar包版本

maven解决代码可重用和便于维护问题

maven把一个完整的项目,分为不同的独立模块,这些模块都有独立坐标,哪个地方需要其中某个模块,直接饮用该模块的坐标即可。
今后如果公司开发一个新项目,我们先考虑的问题不是dao、service、utils、domain如何编写,而是看dao、service、utils、domain这些模块是否存在,若存在,直接引用即可。
我们可以吧拆分零散的模块局喝到一起编写一个完整的项目,这就是聚合思想。

工程和模块的区别
  • 工程不等于完整的项目,模块也不等于完整的项目,一个完整的项目看的是代码,代码完整,就可以说这是一个完整的项目,和此项目是工程和模块没有关系。

  • 工程天生只能使用自己的资源,是独立的。后天可一个其他工程和模块建立关联关系,模块天生是属于父工程的,模块一旦创建,所有父工程的资源都可以使用

  • 子模块之间天生是没有关系的

  • 依赖的jar包可能出现丢失问题

私服配置

maven中setting的配置
存入私服:

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

从私服中下载:

	<profile>
      <id>dev</id>
	  <repositories>
        <repository>
          <id>nexus</id>
          <url>http://localhost:8081/nexus/content/groups/public/</url>
          <releases>
		     <enabled>true</enabled>
		  </releases>
          <snapshots>
		     <enabled>true</enabled>
		  </snapshots>
        </repository>
      </repositories>
	  <pluginRepositories>
	     <pluginRepository>
			 <id>public</id>
             <name>Public Repositories</name>
             <url>http://localhost:8081/nexus/content/groups/public/</url>
		 </pluginRepository>	  
	  </pluginRepositories>     
    </profile>

激活:

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

maven中的配置

<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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值