maven子父级工程学习总结

02maven基础知识回顾
两大核心功能:
依赖管理?
如果当前项目依赖于某些jar包,我们不需要把jar包拷贝当前项目中,而只需要把jar的maven仓库坐标配置到pom.xml中;
一键构建?
通过一个命令就能完成项目的编译、打包、测试、部署…

		生命周期:
			清理周期:
				clean
			默认周期:
				compile、test、package、install、deploy...
				后面的命令执行,那么前面的命令将自动执行;
			站点周期:
				site
				
仓库的分类?
	本地仓库:
		程序员自己电脑上的某个文件夹;
		
	远程仓库(私服):
		在公司的局域网内,找一台电脑,作为maven仓库;
		
	中央仓库:
		maven官方维护的仓库,里面涵盖了几乎所有的开源的jar包;
	

	当我们自己的项目中使用一个jar包的坐标时,查找流程:
		先找本地仓库,如果没找到,再找远程仓库,如果还没找到,最后找中央仓库,如果还没找到,报错;

04maven导入jar包时冲突的解决
同一个jar包(mybatis:3.4.5,3.4.6)被导入了两次;

A--->B---->C---->D
B---->D
什么是直接依赖?
	A直接依赖于B

什么是传递依赖?
	A传递依赖于C
	
	
第一声明原则如何解决jar包冲突?
	哪个配置的pom.xml的前面,哪个优先使用;
	
路径优先原则如何解决jar包冲突?
	哪个依赖的路径短,优先用哪个;
	
直接排除法如何解决jar包冲突?
<exclusions>
      <exclusion>
        <groupId></groupId>
        <artifactId></artifactId>
      </exclusion>
    </exclusions>

05pom文件内标签的讲解
dependencyManagement的作用?
锁定版本(版本管理)

properties标签的作用?
	定义键值对;
	
	
*******************
	pluginManagement用来管理插件版本;

06案例dao层代码编写
需要完成那些java代码和配置文件的编写?

07案例service层代码编写
完成了那些java代码和配置文件?

08案例web层代码编写
完成了哪些java代码和配置文件?

09maven工程拆分与聚合的思想
为什么要把一个项目拆分成多个模块?
为了增强代码的复用性,可维护性
为什么把多个模块聚合成一个项目?
因为多个模块的代码聚合在一起才是一个完整的项目

10maven父子工程的创建
如何创建子模块?
选中父工程,右键选择new module;
parent标签有什么用?
标明当前项目的父工程是谁;

maven
live.longmarch
1.0-SNAPSHOT

modules标签有什么用?
标明当前项目有哪些儿子 ;

maven
live.longmarch
1.0-SNAPSHOT

***************************************
工程内容:
父工程:
parent:
有且仅有一个pom文件,用来做坐标的版本管理以及引入坐标;

			注意点:
				打包方式必须为pom:<packaging>pom</packaging>
		
		
	子工程:
		dao:
			1.写dao相关的内容(java、配置文件);
			2.打包方式是jar
		service:
			1.写service相关的内容(java、配置文件);
			2.打包方式是jar
		web:
			1.写controller相关的内容(java、配置文件、静态资源(html、css、js、jsp。。。));
			2.打包方式是war

11工程和模块的关系以及继承和依赖的概念
在maven父子工程中:
子模块继承父工程;
父工程依赖子模块;

父工程引用子模块的内容:
	不能使用子模块中的内容


子模块引用父工程的内容:
	直接使用父工程的内容

子模块之间相互引用:
	子模块之间不能直接使用;
	A子模块需要使用B子模块中的内容,那么需要在A自模块的pom.xml中引入B子模块才能使用;
		如果A子模块中引入B子模块,那么相当于A子模块中拥有了B子模块中所有的内容;

12传递依赖下来的包是否能用
依赖传递
如有三个项目A、B、C,当前项目为A,A依赖于B,B依赖于C。则项目C在A中是什么样的依赖关系呢?
A传递依赖于C

坐标的依赖范围:
	<scope>compile/runtime/test/provided/system</scope>

如果父模块中配置的坐标的scope范围值是   test、provided、system,子模块中不能直接使用;如果要用,在子模块中自己引入即可。

13在父子工程中填充代码

applicationContext.xml被拆分成几部分?
如何把多个spring配置文件整合到一个配置文件中?

14maven父子工程三种启动方式
1.操作父工程;
2.操作web子模块;
3.部署到本地的tomcat上;

************************
	先install,再tomcat7-run;

如果修改了代码,先clean,再install,最后tomcat7-run

15私服的安装和启动(了解)
如何安装nexus私服?

如何启动nexus服务?
	
库分类:
	hosted?
		
	proxy?
		
	group?

16私服的应用(了解)
如何把本地的应用发布到私服上?
如何把私服上的jar包下载到本地?

******************发布****************************
	1.配置maven的settings.xml
		<servers>
			<server>
				<id>releases</id>
				<username>admin</username>
				<password>admin123</password>
			</server>
			<server>
				<id>snapshots</id>
				<username>admin</username>
				<password>admin123</password>
			</server>
		</servers>

	2.在本地项目的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>


***********************下载***********************************
	在本地maven的settings配置文件中配置:
	<profiles>
		<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> 
			<!--profile的id -->
			<id>bbbb</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>
	  </profiles>

	  <activeProfiles>
			<!--profile的名字-->
			<activeProfile>bbbb</activeProfile>
	  </activeProfiles>

17安装第三方jar包到本地仓库
mvn install:install-file -DgroupId=公司id -DartifactId=项目id -Dversion=版本号
-Dfile=jar包文件本地磁盘路径 -Dpackaging=打包方式

18安装第三方jar包到私服
1.在settings配置文件中添加登录私服第三方登录信息

thirdparty
admin
admin123

2.执行如下命令
mvn deploy:deploy-file -DgroupId=公司id -DartifactId=项目id
-Dversion=版本号 -Dpackaging=打包方式 -Dfile=本地jar路径
-Durl=私服路径 -DrepositoryId=仓库名称

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

发布了71 篇原创文章 · 获赞 1 · 访问量 1162

猜你喜欢

转载自blog.csdn.net/weixin_44993313/article/details/103551081