maven中的pom
- pom的最低要求配置
- pom的默认行为
- packaging有哪些
- 关于
dependency
* - type
- scope
- 关于 Dependency Management
- 构建maven聚合工程,父子工程
- maven官方文档 !!!
pom的最低要求配置
总共5个
project
-根元素modelVersion
-设置为4.0.0
即可groupId
-项目分组的idartifactId
-分组下具体的artifact的idversion
-分组下具体的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的默认行为
- 为什么没有看见常见的配置
<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工程都会自动继承一个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有哪些
jar
(默认)pom
war
ejb
ear
rar
maven-plugin
java-source
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;下面介绍下中间的两个 type
及 scope
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关系一览表:

依赖的传递性可参考:
scope有如下几种:
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在项目的所有路径中都可用。
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或者容器提供支持。
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时,在运行和测试时的类路径过程中需要,但是在编译的类路径过程中不需要。
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的依赖只用于测试阶段(测试阶段编译和执行)的类路径过程中。
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仓库中的依赖。
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>
形如:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-alibaba-dependenciesartifactId>
<version>2.2.9.RELEASEversion>
<type>pomtype>
<scope>importscope>
dependency>
dependencies>
dependencyManagement>
在<dependencymanagement>中的scope为import并且type为pom的依赖dependency本身并不是有效的依赖,但是 :其代表了一系列的实际有效的依赖集合。</dependencymanagement>
在<dependencymanagement>中的scope为import并且type为pom的依赖dependency本身并不是有效的依赖,但是 :其代表了一系列的实际有效的依赖集合。</dependencymanagement>
在<dependencymanagement>中的scope为import并且type为pom的依赖dependency本身并不是有效的依赖,但是 :其代表了一系列的实际有效的依赖集合。</dependencymanagement>
解释:
如上面的依赖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项目需要显示的声明需要使用的依赖,只是不用写版本号而已!</dependencymanagement>
- 示例 1
- 示例 2,
子项目中如何引入类型为pom以及scope为import的依赖
前面已经介绍过import 、 pom类型的依赖,:代表的是一些列有效的依赖的集合。子项目中要引入只需要”ctrl + 左键” 进去后找到对应的依赖集合,选择其中一个或多个引入到子项目即可。




; 构建maven聚合工程,父子工程
- 新建maven项目,packaging选择pom,删除掉出pom.xml以外的文件/文件夹
- 鼠标右键刚才新建的父工程,创建新maven工程。。。
maven官方文档 !!!

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/
转载文章受原作者版权保护。转载请注明原作者出处!