packaging tag in maven pom.xml configuration file

Project packaging type: pom, jar, war

Use the <packing> tag to specify the packaging type, which is the jar type by default.

  • pom: the parent types are all pom types
<packaging>pom</packaging>
  • jar: internal call or service use
<packaging>jar</packaging>
  • war: packaged project for deployment on containers (Tomcat, Jetty, etc.)
<packaging>war</packaging>  

To give an example of packaging type pom:

The project directory structure is as follows:

~/Desktop$ tree -L 4
├── MyProject
│   ├── pom.xml
│   ├── SubProject1
│   │   └── pom.xml
│   ├── SubProject2
│   │   └── pom.xml
│   └── SubProject3
│       └── pom.xml
...

There are three module projects SubProject1, SubProject2, SubProject3 under MyProject. Then we can write the common parts of the three module projects in the pom.xml file of the MyProject project, and then inherit it in the pom.xml of the module project, so that the module project can use the common parts. The pom.xml of the MyProject project is what we call the parent type, and its packaging type should be written as pom, such as:

<project ...>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.wong.tech</groupId>
  <artifactId>myproject</artifactId>
  <packaging>pom</packaging>
  <version>1.0.0</version>
  <name>myproject</name>
  <url>http://maven.apache.org</url>
  <!--模块(有时称作子项目) 被构建成项目的一部分。列出的每个模块元素是指向该模块的目录的相对路径 -->
  <modules>
        <module>SubProject1</module>
        <module>SubProject2</module>
        <module>SubProject3</module>
  </modules>
 ...
  </project>

The pom.xml under MyProject specifies the relative path of the subproject through the <modules> tag. This allows you to execute the mvn command directly in the MyProject project and build all the modules at once. Of course, it is no problem to execute the mvn command in the directory of each module and build one by one.

The pom.xml under the sub-module (subproject) can inherit the pom.xml under MyProject through the <parent> tag, such as the pom.xml of the SubProject1 subproject:

<project
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
        xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <modelVersion>4.0.0</modelVersion>
        <artifactId>myproject-subproject1</artifactId>
        <packaging>jar</packaging>
        <name>myproject-subproject1</name>
        <version>1.0.0</version>
        <url>http://maven.apache.org</url>
        <parent>
                <groupId>com.wong.tech</groupId>
                <artifactId>myproject</artifactId>
                <version>1.0</version>
                <relativePath>../pom.xml</relativePath>
        </parent>
        ...
</project>


Other sub-projects are deduced by analogy.

thanks for reading.

Published 381 original articles · praised 85 · 80,000 views +

Guess you like

Origin blog.csdn.net/weixin_40763897/article/details/105405106