maven中的pom

maven中的pom

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.0modelVersion>

 <groupId>com.mycompany.appgroupId>
 <artifactId>my-appartifactId>
 <version>1version>
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.0modelVersion>
  <groupId>com.xl.testgroupId>
  <artifactId>z-pom-testartifactId>
  <version>1.0-testversion>
project>

maven中的pom
摘自maven官网:

Introduction to the POM

pom的默认行为

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

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

摘自官网: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></repositories>
    <pluginrepositories></pluginrepositories>等等maven中的pom
    所有新建的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>junitgroupId>
      <artifactId>junitartifactId>
      <version>4.12version>
      <type>jartype>
      <scope>testscope>
      <optional>trueoptional>
    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&#x6307;&#x7684;&#x662F;&#x4F9D;&#x8D56;&#x7684;&#x7C7B;&#x578B;&#x3002;&#x8FD9;&#x4E2A;&#x7C7B;&#x578B;&#x4E00;&#x822C;&#x4E0E;&#x4F9D;&#x8D56;&#x7684;&#x6253;&#x5305;&#x65B9;&#x5F0F;&#x662F;&#x4E00;&#x81F4;&#x7684;&#xFF08;&#x5982;&#x679C;type&#x662F;war&#x90A3;&#x4E48;packaging&#x4E5F;&#x662F;war&#xFF09;&#xFF0C;&#x4F46;&#x662F;&#x4E5F;&#x6709;&#x4F8B;&#x5916;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x5BF9;&#x7167;&#x5173;&#x7CFB;&#x53EF;&#x53C2;&#x7167;&#x4E0B;&#x8868;&#xFF1A;

maven中的pom

摘自官网: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&#x7528;&#x4E8E;&#x9650;&#x5236;&#x4F9D;&#x8D56;&#x7684;&#x4F20;&#x9012;&#x6027;&#xFF08;&#x7EA6;&#x675F;&#x4F20;&#x9012;&#x7684;&#x8303;&#x56F4;&#xFF09;&#x4EE5;&#x53CA;&#x5728; &#x7C7B;&#x8DEF;&#x5F84;&#x8FC7;&#x7A0B;&#x4E2D; &#x4F9D;&#x8D56;&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x88AB;&#x5305;&#x542B;&#xFF08;&#x662F;&#x5728;&#x7F16;&#x8BD1;&#x7C7B;&#x8DEF;&#x5F84;&#x8FC7;&#x7A0B;&#xFF1F;&#x6D4B;&#x8BD5;&#x7C7B;&#x8DEF;&#x5F84;&#x8FC7;&#x7A0B;&#xFF1F;&#x8FD8;&#x662F;&#x8FD0;&#x884C;&#x7C7B;&#x8DEF;&#x5F84;&#x8FC7;&#x7A0B;&#xFF1F;&#xFF09;&#x3002;

scope与classpath关系一览表:

maven中的pom

依赖的传递性可参考:

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&#x662F;&#x9ED8;&#x8BA4;&#x7684;scope,&#x5982;&#x679C;&#x4E0D;&#x663E;&#x793A;&#x6307;&#x5B9A;&#x90A3;&#x9ED8;&#x8BA4;&#x5C31;&#x662F;compile.Compile&#x5728;&#x9879;&#x76EE;&#x7684;&#x6240;&#x6709;&#x8DEF;&#x5F84;&#x4E2D;&#x90FD;&#x53EF;&#x7528;&#x3002;

  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&#x4E3A;provided&#x7684;&#x4F9D;&#x8D56;&#x53EA;&#x7528;&#x4E8E;&#x7F16;&#x8BD1;&#x548C;&#x6D4B;&#x8BD5;&#x7684;&#x7C7B;&#x8DEF;&#x5F84;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x5728;&#x8FD0;&#x884C;&#x65F6;&#x6709;JDK&#x6216;&#x8005;&#x5BB9;&#x5668;&#x63D0;&#x4F9B;&#x652F;&#x6301;&#x3002;

  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&#x4E3A;runtime&#x65F6;&#xFF0C;&#x5728;&#x8FD0;&#x884C;&#x548C;&#x6D4B;&#x8BD5;&#x65F6;&#x7684;&#x7C7B;&#x8DEF;&#x5F84;&#x8FC7;&#x7A0B;&#x4E2D;&#x9700;&#x8981;&#xFF0C;&#x4F46;&#x662F;&#x5728;&#x7F16;&#x8BD1;&#x7684;&#x7C7B;&#x8DEF;&#x5F84;&#x8FC7;&#x7A0B;&#x4E2D;&#x4E0D;&#x9700;&#x8981;&#x3002;

  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&#x4E3A;test&#x7684;&#x4F9D;&#x8D56;&#x53EA;&#x7528;&#x4E8E;&#x6D4B;&#x8BD5;&#x9636;&#x6BB5;&#xFF08;&#x6D4B;&#x8BD5;&#x9636;&#x6BB5;&#x7F16;&#x8BD1;&#x548C;&#x6267;&#x884C;&#xFF09;&#x7684;&#x7C7B;&#x8DEF;&#x5F84;&#x8FC7;&#x7A0B;&#x4E2D;&#x3002;

  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&#x4E3A;system&#x7684;&#x4F9D;&#x8D56;&#xFF0C;&#x987B;&#x662F;&#x672C;&#x5730;&#x7CFB;&#x7EDF;&#x7684;&#x4F9D;&#x8D56;(JAR&#x5305;&#x5F62;&#x5F0F;)&#xFF0C;&#x4E0D;&#x80FD;&#x662F;maven&#x4ED3;&#x5E93;&#x4E2D;&#x7684;&#x4F9D;&#x8D56;&#x3002;

  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&#x4E3A;import&#x7684;&#x4F9D;&#x8D56;&#x53EA;&#x7528;&#x4E8E;&#x5143;&#x7D20;<dependencymanagement>,&#x5E76;&#x4E14;&#x4F9D;&#x8D56;&#x7684;type&#x5FC5;&#x987B;&#x4E3A;pom&#x7C7B;&#x578B;</dependencymanagement>
形如:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloudgroupId>
            <artifactId>spring-cloud-alibaba-dependenciesartifactId>
            <version>2.2.9.RELEASEversion>
            <type>pomtype>
            <scope>importscope>
        dependency>
    dependencies>
dependencyManagement>

&#x5728;<dependencymanagement>&#x4E2D;&#x7684;scope&#x4E3A;import&#x5E76;&#x4E14;type&#x4E3A;pom&#x7684;&#x4F9D;&#x8D56;dependency&#x672C;&#x8EAB;&#x5E76;&#x4E0D;&#x662F;&#x6709;&#x6548;&#x7684;&#x4F9D;&#x8D56;&#xFF0C;&#x4F46;&#x662F; &#xFF1A;&#x5176;&#x4EE3;&#x8868;&#x4E86;&#x4E00;&#x7CFB;&#x5217;&#x7684;&#x5B9E;&#x9645;&#x6709;&#x6548;&#x7684;&#x4F9D;&#x8D56;&#x96C6;&#x5408;&#x3002;</dependencymanagement>

&#x5728;<dependencymanagement>&#x4E2D;&#x7684;scope&#x4E3A;import&#x5E76;&#x4E14;type&#x4E3A;pom&#x7684;&#x4F9D;&#x8D56;dependency&#x672C;&#x8EAB;&#x5E76;&#x4E0D;&#x662F;&#x6709;&#x6548;&#x7684;&#x4F9D;&#x8D56;&#xFF0C;&#x4F46;&#x662F; &#xFF1A;&#x5176;&#x4EE3;&#x8868;&#x4E86;&#x4E00;&#x7CFB;&#x5217;&#x7684;&#x5B9E;&#x9645;&#x6709;&#x6548;&#x7684;&#x4F9D;&#x8D56;&#x96C6;&#x5408;&#x3002;</dependencymanagement>

&#x5728;<dependencymanagement>&#x4E2D;&#x7684;scope&#x4E3A;import&#x5E76;&#x4E14;type&#x4E3A;pom&#x7684;&#x4F9D;&#x8D56;dependency&#x672C;&#x8EAB;&#x5E76;&#x4E0D;&#x662F;&#x6709;&#x6548;&#x7684;&#x4F9D;&#x8D56;&#xFF0C;&#x4F46;&#x662F; &#xFF1A;&#x5176;&#x4EE3;&#x8868;&#x4E86;&#x4E00;&#x7CFB;&#x5217;&#x7684;&#x5B9E;&#x9645;&#x6709;&#x6548;&#x7684;&#x4F9D;&#x8D56;&#x96C6;&#x5408;&#x3002;</dependencymanagement>

解释:

如上面的依赖spring-cloud-alibaba-dependencies并不是有效的依赖,而是spring-cloud-alibaba的一系列的有效依赖的集合的代表:

maven中的pom
maven中的pom

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

关于 Dependency Management

  • &#x4E00;&#x822C;&#x7528;&#x4E8E;parent&#x9879;&#x76EE;&#x7684;pom&#x4E2D;
  • &#x597D;&#x5904;&#xFF1A;
    1. &#x6709;&#x591A;&#x4E2A;child&#x9879;&#x76EE;&#x7EE7;&#x627F;&#x540C;&#x4E00;&#x4E2A;parent&#x9879;&#x76EE;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x907F;&#x514D;&#x5728;&#x6BCF;&#x4E00;&#x4E2A;&#x9879;&#x76EE;&#x4E2D;&#x90FD;&#x58F0;&#x660E;&#x7248;&#x672C;&#x53F7;&#xFF0C;&#x53EA;&#x9700;&#x5728;parent&#x9879;&#x76EE;&#x4E2D;&#x58F0;&#x660E;&#x5373;&#x53EF;&#xFF1B;
    2. &#x9700;&#x8981;&#x4FEE;&#x6539;&#x7248;&#x672C;&#x65F6;&#xFF0C;&#x4E5F;&#x53EA;&#x9700;&#x4FEE;&#x6539;parent&#x9879;&#x76EE;&#x4E2D;&#x7684;&#x7248;&#x672C;&#x5373;&#x53EF;
    3. &#x67D0;&#x4E00;&#x4E2A;child&#x9879;&#x76EE;&#x9700;&#x8981;&#x4E0D;&#x4E00;&#x6837;&#x7684;&#x7248;&#x672C;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x5728;&#x81EA;&#x5DF1;&#x7684;&#x9879;&#x76EE;&#x4E2D;&#x5355;&#x72EC;&#x52A0;&#x4E0A;&#x7248;&#x672C;&#x53F7;&#x5373;&#x53EF;
  • &#x6CE8;&#x610F;&#xFF01;&#xFF01;&#xFF01;<dependencymanagement>&#x91CC;&#x9762;&#x53EA;&#x662F;&#x58F0;&#x660E;&#x4F9D;&#x8D56;&#xFF0C;&#x5E76;&#x4E0D;&#x5F15;&#x5165;&#x5B9E;&#x73B0;&#xFF0C;&#x6240;&#x4EE5;child&#x9879;&#x76EE;&#x9700;&#x8981;&#x663E;&#x793A;&#x7684;&#x58F0;&#x660E;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x7684;&#x4F9D;&#x8D56;&#xFF0C;&#x53EA;&#x662F;&#x4E0D;&#x7528;&#x5199;&#x7248;&#x672C;&#x53F7;&#x800C;&#x5DF2;&#xFF01;</dependencymanagement>
  • 示例 1
    maven中的pom
    maven中的pom
  • 示例 2, &#x5B50;&#x9879;&#x76EE;&#x4E2D;&#x5982;&#x4F55;&#x5F15;&#x5165;&#x7C7B;&#x578B;&#x4E3A;pom&#x4EE5;&#x53CA;scope&#x4E3A;import&#x7684;&#x4F9D;&#x8D56;

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

maven中的pom
maven中的pom
maven中的pom
maven中的pom

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

  1. 新建maven项目,packaging选择pom,删除掉出pom.xml以外的文件/文件夹
    maven中的pom
  2. 鼠标右键刚才新建的父工程,创建新maven工程。。。
    maven中的pom
    maven中的pom

maven官方文档 !!!

POM Reference

maven中的pom

Original: https://blog.csdn.net/qq_29025955/article/details/128409503
Author: 爱看老照片
Title: maven中的pom



相关阅读

Title: EasyOCR 因不兼容产生的 ValueError 与 AttributeError

基于 jupyter-lab,第一次在 python 中使用 EasyOCR 时,发生两个异常。测试图片如下:

1. ValueError: Invalid input type. Supporting format = string(file path or url), bytes, numpy array

运行代码:

import easyocr
from pathlib import Path
WORK_PATH = Path('E:/test')
WORK_FILE = '图片_1.jpg'
reader = easyocr.Reader(['ch_sim', 'en'], gpu = False)
result = reader.readtext((WORK_PATH / WORK_FILE), detail = 0)
result

生成以下异常(第一个异常):

[En]

The following exception is generated (the first exception):

ValueError: Invalid input type. Supporting format = string(file path or url), bytes, numpy array

发生此 ValueError 异常的原因是 pathlib 与 EasyOCR 的不兼容。修改代码如下,则出现 AttributeError (下一个异常)。

import easyocr
from pathlib import Path
WORK_PATH = Path('E:/test')
WORK_FILE = '图片_1.jpg'
reader = easyocr.Reader(['ch_sim', 'en'], gpu = False)
result = reader.readtext((WORK_PATH / WORK_FILE).as_posix(), detail = 0)
result
AttributeError: 'NoneType' object has no attribute 'shape'

2. AttributeError: ‘NoneType’ object has no attribute ‘shape’

发生此 AttributeError 异常的原因竟然是 文件名有中文 含有中文。修改文件名如下,则代码正常:

import easyocr
from pathlib import Path
WORK_PATH = Path('E:/test')
WORK_FILE = 'pic_1.jpg'
reader = easyocr.Reader(['ch_sim', 'en'], gpu = False)
result = reader.readtext((WORK_PATH / WORK_FILE).as_posix(), detail = 0)
result

内容输出如下:

['EasyoCR测试图片',
 'TIOBE排行榜是根据互联网上有经验的程序员',
 '课程和第三方',
 '厂商的数量',
 '并使用搜索引擎 (如Google Bing',
 'Yahoo!)',
 '以及',
 'Wikipedia',
 'Amazon',
 'YouTube和Baidu (百度)统计出排名数据,',
 '只是反映某个编程语言的热门程度。并不能说明一门编程语言好不',
 '好。或者一门语言所编写的代码数量多少',
 '人生苦短。我用 Python',
 '序号',
 '编程语言',
 '分数',
 'Python',
 '大大大大大',
 '2',
 'C',
 '大大大大众',
 '3',
 'JAVA',
 '大大大众众',
 '4',
 'C ++',
 '大大众众众',
 '5',
 'C#',
 '大众众众众']

Original: https://blog.csdn.net/ray9550/article/details/124562617
Author: ray9550
Title: EasyOCR 因不兼容产生的 ValueError 与 AttributeError

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/355491/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • python盒中取球_Python基于pygame实现的弹力球效果(附源码)

    本文实例讲述了Python基于pygame实现的弹力球效果。分享给大家供大家参考,具体如下: 运行效果: 代码部分如下: A bouncing ball import sys, p…

    Python 2023年1月22日
    017
  • 时序数据库进入云原生时代,TDengine 3.0 三大创新详解

    在 8 月 13 日的 TDengine 开发者大会上,涛思数据创始人陶建辉进行了题为《高性能、云原生的极简时序数据处理平台》的主题演讲。在本次演讲中,他不仅分享了时序数据库现阶段…

    2022年9月3日
    0103
  • java 调用 scrapy_使用基于python scrapy的爬虫但收到错误

    嗨伙计们我在python中写了一个爬虫来刮…… import scrapy from c2.items import C2Item try: class C…

    Python 2023年1月26日
    025
  • 关于Focal loss损失函数的代码实现

    Focal loss的公式:其中用到的交叉熵损失函数表达式是(3) F L ( p t ) = − ( 1 − p t ) γ log ⁡ p t (1) FL(p_{t}) = …

    Python 2023年1月24日
    025
  • Django+Vue环境搭建

    一、Django环境 1、下载Django pip install django 2、创建Django项目 django-admin startproject server #se…

    Python 2022年12月26日
    033
  • 请求量太大扛不住怎么办?进来学一招

    hello,大家好呀,我是小楼。 上篇文章《一言不合就重构》 说了我最近重构的一个系统,虽然重构完了,但还在灰度,这不,在灰度过程中又发现了一个问题。 背景 这个问题简单说一下背景…

    Python 2023年1月19日
    031
  • 数据分析 — Pandas②

    目录 数据筛选 给数据打标签 行的查改增删 * 查看行 – 索引 分片 iloc 修改行 – 情况一 情况二 新增行 删除行 数据的分组 数据筛选 沿用上一…

    Python 2023年1月9日
    024
  • 使用python自带的http server共享文件

    # 采用默认端口(8000)建立HTTP服务 $ python -m http.server # 采用自定端口(8765)建立HTTP服务 $ python -m http.ser…

    2022年8月9日
    0200
  • pytest-logging使用

    – – coding: utf-8 –– import loggingimport osimport sys import time…

    Python 2023年1月17日
    020
  • PyTorch——Tensors

    Tensors是一种特殊的数据结构,类似于数组和矩阵。在PyTorch中我们使用Tensors对模型以及模型参数的输入和输出进行编码。 Tensors类似于NumPy中的ndarr…

    Python 2023年1月12日
    021
  • python 虚拟环境

    pipenv 工作流 Pipenv是基于pip的Python包管理工具,它和pip的用法非常相似,可以看作pip的加强版,它的出现解决了旧的pip+virtualenv+requi…

    Python 2023年1月2日
    055
  • 手把手搭建经典神经网络系列(1)——AlexNet

    在绘制森林图之前当然需要先下载RStudio软件啦,在下载后需要安装对应的rtool,最后将两者关联起来才能使用其中对应的包,否则只安装了软件很多功能不能使用而且还会报错,这篇文章…

    Python 2023年1月23日
    018
  • 设计模式之状态模式

    实际开发中订单往往都包含着订单状态,用户每进行一次操作都要切换对应的状态,而每次切换判断当前的状态是必须的,就不可避免的引入一系列判断语句,为了让代码更加清晰直观,我们引入今天的主…

    Python 2023年1月31日
    014
  • Ai studio 使用教程:

    Ai studio地址:飞桨AI Studio – 人工智能学习实训社区 (baidu.com) 使用 Ai studio 的算力需要相应的算力卡,进行登陆注册后可领取…

    Python 2023年1月23日
    017
  • Python安装matplotlib

    方法一首先确保已经安装python,然后用pip来安装matplotlib模块。 进入到cmd窗口下,执行python -m pip install -U pip setuptoo…

    Python 2023年1月14日
    042
  • Python全局变量跨模块变量定义和使用

    在同一个py脚本中,定义在所有函数之外的变量可以理解为全局变量,因为所有函数可以直接访问函数外的变量(但不能访问其他函数的私有变量),这里涉及到变量的作用域,一般分为函数作用域和全…

    Python 2023年1月10日
    045
最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总