maven中的pom

news2025/7/7 10:21:44

maven中的pom

  • pom的最低要求配置
  • pom的默认行为
  • packaging有哪些
  • 关于```dependency```
    • type
    • scope
  • 关于 Dependency Management
  • 构建maven聚合工程,父子工程
  • maven官方文档 !!!

pom的最低要求配置

总共5个

  1. project-根元素
  2. modelVersion -设置为4.0.0即可
  3. groupId-项目分组的id
  4. artifactId-分组下具体的artifact的id
  5. version-分组下具体的artifact的版本

3 4 5称为组成maven的坐标 gav

形如:

<project>
 <modelVersion>4.0.0</modelVersion>

 <groupId>com.mycompany.app</groupId>
 <artifactId>my-app</artifactId>
 <version>1</version>
</project>

实例:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.xl.test</groupId>
  <artifactId>z-pom-test</artifactId>
  <version>1.0-test</version>
</project>

在这里插入图片描述
摘自maven官网:

Introduction to the POM

pom的默认行为

  • 为什么没有看见常见的配置<packaging>war</packaging>

<packaging>属于maven的一个默认配置项,如果不配置则默认打包方式为jar,也可显示的配置为:<packaging>jar</packaging>

摘自官网:Introduction to the POM 之 Minimal POM

Also, as mentioned in the first section, if the configuration details are not specified, Maven will use their defaults. One of these default values is the packaging type. 
Every Maven project has a packaging type. If it is not specified in the POM, then the default value "jar" would be used
  • 为什么Eclipse中的打开pom.xml文件点击“Effective POM”多次许多内容?<repositories>
    <pluginRepositories>等等在这里插入图片描述
    所有新建的maven工程都会自动继承一个super pom.xml, 上图中多出来的这些内容都是maven自带的默认的super pom.xml。
The Super POM is Maven's default POM. All POMs extend the Super POM unless explicitly set, meaning the configuration specified in the Super POM is inherited by the POMs you created for your projects.

You can see the Super POM for Maven 3.6.3 in Maven Core reference documentation.

摘自官网:Introduction to the POM 之 Super POM

packaging有哪些

  1. jar(默认)
  2. pom
  3. war
  4. ejb
  5. ear
  6. rar
  7. maven-plugin
  8. java-source
  9. javadoc

关于dependency

元素包含:

  • groupId
  • artifactId
  • version
  • type
  • scope
  • optional
  • classifier
  • systemPath

形如:

 	<dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <type>jar</type>
      <scope>test</scope>
      <optional>true</optional>
    </dependency>

前3个前面已经介绍,后面3个参考官网:POM Reference中的Dependencies;下面介绍下中间的两个typescope

type

Corresponds to the chosen dependency type. This defaults to jar. While it usually represents the extension on the filename 
of the dependency, that is not always the case: a type can be mapped to a different extension and a classifier. The type 
often corresponds to the packaging used, though this is also not always the case. Some examples are jar, ejb-client and
 test-jar: see default artifact handlers for a list. New types can be defined by plugins that set extensions to true, so this is 
 not a complete list.

大致翻译:
type指的是依赖的类型。这个类型一般与依赖的打包方式是一致的(如果type是war那么packaging也是war),但是也有例外的情况,对照关系可参照下表:
在这里插入图片描述

摘自官网:POM Reference中的Dependencies

scope

Dependency scope is used to limit the transitivity of a dependency and to determine when a dependency is included in a classpath.

翻译:
scope用于限制依赖的传递性(约束传递的范围)以及在 类路径过程中 依赖什么时候被包含(是在编译类路径过程?测试类路径过程?还是运行类路径过程?)。

scope与classpath关系一览表:
在这里插入图片描述

依赖的传递性可参考:

maven高级——依赖的传递性

Maven依赖传递

scope有如下几种:

  1. compile
This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. 
Furthermore, those dependencies are propagated to dependent projects

compile是默认的scope,如果不显示指定那默认就是compile.Compile在项目的所有路径中都可用。

  1. provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For 
example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet 
API and related Java EE APIs to scope provided because the web container provides those classes. A dependency with 
this scope is added to the classpath used for compilation and test, but not the runtime classpath. It is not transitive.

scope为provided的依赖只用于编译和测试的类路径过程中,在运行时有JDK或者容器提供支持。

  1. runtime
This scope indicates that the dependency is not required for compilation, but is for execution. Maven 
includes a dependency with this scope in the runtime and test classpaths, but not the compile classpath.

scope为runtime时,在运行和测试时的类路径过程中需要,但是在编译的类路径过程中不需要。

  1. test
This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. This scope is not transitive. Typically this scope is used for test libraries such as JUnit and Mockito. It is also used for non-test libraries such as Apache Commons IO if those libraries are used in unit tests (src/test/java) but not in the model code (src/main/java).

scope为test的依赖只用于测试阶段(测试阶段编译和执行)的类路径过程中。

  1. system
This scope is similar to provided except that you have to provide the JAR which 
contains it explicitly. The artifact is always available and is not looked up in a repository.

scope为system的依赖,须是本地系统的依赖(JAR包形式),不能是maven仓库中的依赖。

  1. import
This scope is only supported on a dependency of type pom in the 
<dependencyManagement> section. It indicates the dependency is to be replaced with 
the effective list of dependencies in the specified POM's <dependencyManagement> 
section. Since they are replaced, dependencies with a scope of import do not 
actually participate in limiting the transitivity of a dependency.

scope为import的依赖只用于元素<dependencyManagement>,并且依赖的type必须为pom类型
形如:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>2.2.9.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

在<dependencyManagement>中的scope为import并且type为pom的依赖dependency本身并不是有效的依赖,但是 :其代表了一系列的实际有效的依赖集合。

在<dependencyManagement>中的scope为import并且type为pom的依赖dependency本身并不是有效的依赖,但是 :其代表了一系列的实际有效的依赖集合。

在<dependencyManagement>中的scope为import并且type为pom的依赖dependency本身并不是有效的依赖,但是 :其代表了一系列的实际有效的依赖集合。

解释:

如上面的依赖spring-cloud-alibaba-dependencies并不是有效的依赖,而是spring-cloud-alibaba的一系列的有效依赖的集合的代表:
在这里插入图片描述
在这里插入图片描述

摘自官网:Introduction to the Dependency Mechanism 之 Dependency Scope

关于 Dependency Management

  • 一般用于parent项目的pom中‘’
  • 好处:
    1. 有多个child项目继承同一个parent项目时,可以避免在每一个项目中都声明版本号,只需在parent项目中声明即可;
    2. 需要修改版本时,也只需修改parent项目中的版本即可
    3. 某一个child项目需要不一样的版本,只需要在自己的项目中单独加上版本号即可
  • 注意!!!<dependencyManagement>里面只是声明依赖,并不引入实现,所以child项目需要显示的声明需要使用的依赖,只是不用写版本号而已!
  • 示例 1
    在这里插入图片描述
    在这里插入图片描述
  • 示例 2, 子项目中如何引入类型为pom以及scope为import的依赖

前面已经介绍过import 、 pom类型的依赖,:代表的是一些列有效的依赖的集合。子项目中要引入只需要“ctrl + 左键” 进去后找到对应的依赖集合,选择其中一个或多个引入到子项目即可。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

构建maven聚合工程,父子工程

  1. 新建maven项目,packaging选择pom,删除掉出pom.xml以外的文件/文件夹
    在这里插入图片描述

  2. 鼠标右键刚才新建的父工程,创建新maven工程。。。
    在这里插入图片描述
    在这里插入图片描述

maven官方文档 !!!

POM Reference
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/109349.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Polygon zkEVM发布公开测试网2.0

1. 引言 Polygon zkEVM发布公开测试网2.0&#xff0c;相比于10月份发布的公开测试网1.0版本&#xff0c;做了如下改进&#xff1a; 支持递归证明&#xff08;testnet1.0采用的是one batch of transactions对应one proof&#xff09;&#xff1a;从而支持多个provers并行工作&…

【架构师(第五十三篇)】 性能优化之 HTTP 缓存

ETag ETagHTTP 响应头是资源的特定版本的标识符&#xff0c;这可以让缓存更高效&#xff0c;并节省带宽&#xff0c;因为如果内容没有改变&#xff0c;web 服务器不需要发送完整的响应。 第二次请求的时候会添加一个 If-None-Match 请求头&#xff0c;去判断文件是否发生过变化…

[思维模式-11]:《如何系统思考》-7- 认识篇 - 克服片面、局部思维,转向全面思考 =》 UML

目录 第1章 全面思考概述&#xff08;空间&#xff09; 1.1 什么是全面思考&#xff08;整体思考&#xff09; 1.2 全面思考的含义 1.3 程序的局部性原理 第2章 如何做到全面思考 2.1 本位思考 》 全局思考 2.2 大局观&#xff0c;既是一种格局&#xff0c;也是一种能力…

【SpringMVC】下篇,拦截器(一步到位学会它)

✅作者简介&#xff1a;热爱Java后端开发的一名学习者&#xff0c;大家可以跟我一起讨论各种问题喔。 &#x1f34e;个人主页&#xff1a;Hhzzy99 &#x1f34a;个人信条&#xff1a;坚持就是胜利&#xff01; &#x1f49e;当前专栏&#xff1a;【Spring】 &#x1f96d;本文内…

Java项目:springboot私人牙医管理系统

作者主页&#xff1a;源码空间站2022 简介&#xff1a;Java领域优质创作者、Java项目、学习资料、技术互助 文末获取源码 项目介绍 私人牙医管理系统。该项目分为前后台&#xff0c;共三种角色&#xff1a;管理员、医生、客户&#xff1b; 前台主要功能包括&#xff1a;首页、…

【记录】Tiff图像的前处理,median blur filter 及 linear stretch

文章目录读取Tiffmedian blur filter 中值滤波器替换百分位值值域变成[0,255]从Google Earth Engine上下载的sentinel-1遥感影像(float32)。对于SAR影像在使用前可以做如下前处理&#xff1a;去除SAR噪点替换百分位2%以下及百分位98%以上的点linear stretch 将sentinel-1的值域…

【web3】使用web3.js发布并执行智能合约

前言 昨天我们学习了使用 web3.js 库查询链上区块和交易的用法&#xff0c;今天我们来介绍一下使用 web3.js 与智能合约的交互。在学习本节前&#xff0c;你应该对智能合约有一定的了解。 智能合约的生命周期包括 创建、发布、执行 以及 销毁。 创建&#xff1a;在 Remix 中…

华为云CDN,助力电商平台无惧流量洪峰

对于电子商务平台来说&#xff0c;接连不断的促销活动支撑着电子商务的基本运作&#xff0c;并且频率越来越高。618、双11、双12等越来越多的购物节创造了消费高峰&#xff0c;这就要求企业的网络基础设施能够承受住用户流量的洪峰。 目前&#xff0c;电子商务在网站运营上常常…

JavaWeb学习之MVC、jstl、El表达式06

目录 1.MVC:开发模式 2 mvc三层架构 2.EL表达式 1.使用 2.获取值 1.${域名称.键名} 2 ${键名} 3.隐式对象 3.jstl学习 1.概念 2.作用 3.使用步骤 4,常用的]STL标签 1.MVC:开发模式 1.jsp演变历史 1,早期只有servlet,只能使用response输出标签数据&#xff0c;非常…

艾美捷 24孔细胞划痕试验试剂盒检测原理说明

受伤的组织会引发一系列复杂而结构化的事件&#xff0c;以修复受损的组织区域这些事件可能包括血管生成因子增加血管化增殖和细胞外基质沉积&#xff0c;以及炎症免疫细胞的浸润破坏坏死组织的过程。伤口愈合过程开始于细胞向伤口&#xff0c;开始突出&#xff0c;迁移&#xf…

Html+JavaScript+Css 二手车价格评估系统设计开发

目录 一、系统设计技术及平台介绍 二、系统总体设计图 三、软件模块实现 3.1 登陆注册模块 3.2 主界面 3.3 车辆评估界面 3.4 评估记录界面 3.5 评估结果界面 3.6 个人信息界面 四、数据库实体设计 五、重置成本法简介 六、相关代码 6.1 登陆界面代码 6.2 主界面…

【TypeScript】TS安装与使用

目录 初识TypeScript TypeScript给JS添加类型支持的原因 TypeScript相比JS的优势 TS工具包的安装 TS文件的编译和运行 简化TS的运行步骤 初识TypeScript TypeScript&#xff08;简称&#xff1a;TS&#xff09;是JavaScript的超集&#xff08;JS有的TS都有&#xff09;。…

Python编程 制作一个超级浪漫的新年倒计时(附源代码)

作者简介&#xff1a;一名在校计算机学生、每天分享Python的学习经验、和学习笔记。 座右铭&#xff1a;低头赶路&#xff0c;敬事如仪 个人主页&#xff1a;网络豆的主页​​​​​​ 目录 前言 一.新年介绍 二.代码介绍 1.应用的技术 &#xff08;1&#xff09;Pyga…

Java项目:springboot电影推荐网站

作者主页&#xff1a;源码空间站2022 简介&#xff1a;Java领域优质创作者、Java项目、学习资料、技术互助 文末获取源码 项目介绍 springboot电影推荐网站。本系统采用企业级开发标准&#xff0c;使用SpringBoot架构&#xff0c;数据访问层采用Spring Data Jpa&#xff0c;业…

工具(二):Nginx 扩展 OpenResty

OpenResty 介绍OpenResty 原理Nginx 模块Nginx的 lua插载点案例 配置模板nginx.conf通过Lua找到静态文件 — 商品页通过Lua 获取 redis 只返回 — 库存test 其他Demo MysqlOps.luaRedisExtOps.luaredisOps.lua 辅助工具类说明 自动生成静态页FTP 工具 Nginx_有5大优点&#x…

职场经验:游戏测试的主要工作及主要流程

01 游戏测试主要内容 1、功能测试 功能测试是游戏测试中最常见的模式&#xff0c;主要测试方法为黑盒测试 功能测试主要用来验证功能是否符合需求设计 功能测试主要考虑正确性&#xff0c;而不考虑游戏底层结构及代码错误 功能测试通常从界面着手开始测试&#xff0c;尽量…

【架构师(第五十一篇)】 服务端开发之技术方案设计

接口设计 把 server 端当做一个黑盒&#xff0c;它将如何与前端通讯&#xff1f; 功能范围 B 端&#xff0c;用户注册&#xff0c;作品管理&#xff0c;模板管理编辑器&#xff0c;单个作品的内容获取&#xff0c;修改&#xff0c;预览和发布 功能拆分 用户信息相关作品管…

线上牛奶配送

开发工具(eclipse/idea/vscode等)&#xff1a; 数据库(sqlite/mysql/sqlserver等)&#xff1a; 功能模块(请用文字描述&#xff0c;至少200字)&#xff1a; 基于Java的线上牛奶配送系统的设计与实现 风网站前台&#xff1a;网站介绍、联系我们、公告信息、套餐类型、牛奶套餐、…

Linux-4 文件管理

Linux-4 文件管理 文件管理概述 谈到Linux文件管理&#xff0c;首先我们需要了解的是&#xff0c;我们要对文件做些什么事&#xff1f;其实无非就是对一个文件进行创建&#xff0c;复制&#xff0c;移动&#xff0c;查看&#xff0c;编辑&#xff0c;压缩&#xff0c;查找&am…

自己个人拥有一个可以支付功能的网站?当然可以了!保姆级演示!

文章目录前提条件演示应用申请开通和配置应用创建应用配置代码开发后端实例前端代码实例源码前提条件 这是必要条件&#xff01;&#xff01;&#xff01; 这是必要条件&#xff01;&#xff01;&#xff01; 这是必要条件&#xff01;&#xff01;&#xff01; 开通当面付&am…