温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

maven的pom介绍及配置是什么

发布时间:2021-10-21 09:43:02 来源:亿速云 阅读:150 作者:柒染 栏目:大数据

这期内容当中小编将会给大家带来有关maven的pom介绍及配置是什么,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

1.什么是pom?

pom(Project Object Model,项目对象模型)定义了项目的基本信息,用于描述项目是如何构建,声明项目依赖,插件配置,仓库配置等等。

2.pom配置

Xml代码

<project xmlns="http://maven.apache.org/POM/4.0.0" 2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemalocation="http://maven.apache.org/POM/4.0.0  
 4             http://maven.apache.org/xsd/maven-4.0.0.xsd">  
 5     <modelversion>4.0.0</modelversion>          
 6       
 7     <!-- 坐标 -->  
	   <parent> ... </parent>  
 8     <groupid>...</groupid>   
 9     <artifactid>...</artifactid>  
10     <version>...</version>  
11     <packaging>...</packaging>  
	   <!-- 仓库依赖 -->  
12     <dependencies>...</dependencies>  
14     <dependencymanagement>...</dependencymanagement>  
	   <!-- 项目模块配置 -->  
15     <modules>...</modules>  
	   <!-- 全局配置文件 -->  
16     <properties>...</properties>  
17       
18     <!-- 构建过程的设置 -->  
19     <build>...</build>  
20     <reporting>...</reporting>  
21       
22     <!-- 项目信息设置 -->  
23     <name>...</name>  
24     <description>...</description>  
25     <url>...</url>  
26     <inceptionyear>...</inceptionyear>  
27     <licenses>...</licenses>  
28     <organization>...</organization>  
29     <developers>...</developers>  
30     <contributors>...</contributors>  
31       
32     <!-- 环境设置 -->  
33     <issuemanagement>...</issuemanagement>  
34     <cimanagement>...</cimanagement>  
35     <mailinglists>...</mailinglists>  
36     <scm>...</scm>  
37     <prerequisites>...</prerequisites>  
38     <repositories>...</repositories>  
39     <pluginrepositories>...</pluginrepositories>  
40     <distributionmanagement>...</distributionmanagement>  
41     <profiles>...</profiles>  
42 </project>

3.pom标签详解

3.1 项目坐标标签:

1.  <project xmlns="[http: maven.apache.org pom 4.0.0](http: 4.0.0)" 2. xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)" 3. xsi:schemalocation="[http://maven.apache.org/POM/4.0.0](http://maven.apache.org/POM/4.0.0)

4.  [http://maven.apache.org/maven-v4\_0\_0.xsd](http://maven.apache.org/maven-v4_0_0.xsd)">

5.  <modelversion>4.0.0</modelversion>

6.  <groupid>org.codehaus.mojo</groupid>

7.  <artifactid>my-project</artifactid>

8.  <version>1.0</version>

9.  <packaging>war</packaging>

10.  

11.  groupId : 组织标识,例如:org.codehaus.mojo,在M2_REPO目录下,将是: org/codehaus/mojo目录。

12.  artifactId : 项目名称,例如:my-project,在M2_REPO目录下,将是:org/codehaus/mojo/my-project目录。

13.  version : 版本号,例如:1.0,在M2_REPO目录下,将是:org/codehaus/mojo/my-project/1.0目录。

14.  packaging : 打包的格式,可以为:pom , jar , maven-plugin , ejb , war , ear , rar , par

15.  modelVersion:定义pom版本号,版本号有一系列的规则

3.2 依赖标签:

(依赖关系列表(dependency list)是POM的重要部分,也就是我们项目对jar包的管理)

Xml代码

1.  <dependencies>

2.  <dependency>

3.  <groupid>junit</groupid>

4.  <artifactid>junit</artifactid>

5.  <version>4.0</version>

6.  <scope>test</scope>

7.  </dependency>

8.  …

9.  </dependencies>

10.  groupId , artifactId , version :引用的坐标

11.  scope : compile(default),provided,runtime,test,system &nbsp;依赖的范围

12.  exclusions &nbsp;需要排除的依赖的jar包

3.3 继承和聚合(子pom对父pom依赖 和 父项目对模块的依赖)

1.  <project xmlns="[http: maven.apache.org pom 4.0.0](http: 4.0.0)" 2. xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)" 3. xsi:schemalocation="[http://maven.apache.org/POM/4.0.0](http://maven.apache.org/POM/4.0.0)
4.  [http://maven.apache.org/maven-v4\_0\_0.xsd](http://maven.apache.org/maven-v4_0_0.xsd)">
5.  <modelversion>4.0.0</modelversion>
6.  <groupid>org.maven.my</groupid>
7.  <artifactid>${projectName}-parent</artifactid>
8.  <version>2.0</version>
9.  <!--\-\- 定义项目有哪些子模块 ---->
10.  <modules>
11.  <module>my-spring-web<module>
12.  <module>my-spring-service<module>
13.  <module>my-spring-common<module>
14.  <module>my-spring-dao<module>
15.  </module></module></module></module></module></module></module></module></modules>
16.

 3.4 项目构建build时标签:

(可以帮我们指定 需要的maven插件,主要标签:Resources和Plugins

Resources:用于排除或包含某些资源文件

可以用于解决 我们部署测试和线上 服务时,资源文件配置的隔离依赖:-Ponline | -Plocal

Xml代码

1.  <build>
2.  <!-- 开启资源文件过滤 -->
3.  <resources>
4.  <resource>
5.  <directory>${project.basedir}/src/main/resources</directory>
6.  <filtering>true</filtering>
7.  </resource>
8.  </resources>
9.  </build>
10.  <!-- 指定资源文件路径 -->
11.  <profiles>
12.  <!--测试配置 -->
13.  <profile>
14.  <id>local</id>
15.  <activation>
16.  <activebydefault>true</activebydefault>
17.  </activation>
18.  <build>
19.  <filters>
20.  <filter>${project.basedir}/src/main/swap/local.properties</filter>
21.  </filters>
22.  </build>
23.  </profile>
24.  <!-- 线上配置 -->
25.  <profile>
26.  <id>online</id>
27.  <activation>
28.  <activebydefault>false</activebydefault>
29.  </activation>
30.  <build>
31.  <filters>
32.  <filter>${project.basedir}/src/main/swap/online.properties</filter>
33.  </filters>
34.  </build>
35.  </profile>

Plugins:设置构建的插件

1.  <build>
2.  …
3.  <!--\-\- 配置maven在运行时 需要依赖的插件,我们平常可以配jetty插件或者assemebly插件等---->
4.  <plugins>
5.  <plugin>
6.  <groupid>org.apache.maven.plugins</groupid>
7.  <artifactid>maven-jar-plugin</artifactid>
8.  <version>2.0</version>
9.  <extensions>false</extensions>
10.  <inherited>true</inherited>
11.  <configuration>
12.  <classifier>test</classifier>
13.  </configuration>
14.  <dependencies>…</dependencies>
15.  <executions>…</executions>
16.  </plugin>

上述就是小编为大家分享的maven的pom介绍及配置是什么了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI