maven的pom.xml各種情況的說明
現在的maven使用基本都是採用多模塊的形式,父模塊 -> 子模塊(或父模塊 -> 子模塊)
目錄結構
目錄說明:
- 【03-maven-test】:是父模塊
- 【03-test-module】:子模塊,另一個父模塊
- 【03-test-java】:子模塊
- 【03-test-web】:【03-test-module】的子模塊
- 【03-test-web-child】:【03-test-module】的子模塊
各個配置
03-maven-test:
<?xml version="1.0" encoding="UTF-8"?>
<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.sm</groupId>
<artifactId>03-maven-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>test</description>
<name>03-maven-test</name>
<packaging>pom</packaging> <!--pom、war、jar, 默認jar-->
<modules> <!--子模塊-->
<module>03-test-module</module>
<module>03-test-java</module>
</modules>
<properties>
<!-- springframe 版本控制 -->
<spring.version>4.1.6.RELEASE</spring.version>
<avro.version>1.7.7</avro.version>
</properties>
<dependencyManagement> <!-- <dependencies>中的jar直接加到項目中,管理的是依賴關係(如果有父pom,子pom,則子pom中只能被動接受父類的版本);<dependencyManagement>主要管理版本,對於子類繼承同一個父類是很有用的,集中管理依賴版本不添加依賴關係,對於其中定義的版本,子pom不一定要繼承父pom所定義的版本。-->
<dependencies>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>${avro.version}</version>
<scope>compile</scope> <!--compile、test 、runtime 、provided 、system 、import, 默認compile-->
<type>jar</type> <!--默認jar-->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- springframe end -->
<!--log4j日誌包 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- JUnit單元測試工具 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<!-- aspectJ AOP 織入器 -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
<!-- jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- JSON: jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jr</groupId>
<artifactId>jackson-jr-all</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.60</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies> <!--可以和dependencyManagement同時存在-->
<dependency>
<groupId>com.suning.saltcm</groupId>
<artifactId>acm-client</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
<build>
<finalName>03-maven-test</finalName>
<pluginManagement> <!-- 效果同 dependencyManagement -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
03-test-java:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>03-maven-test</artifactId>
<groupId>com.sm</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.sm</groupId>
<artifactId>03-test-java</artifactId>
<name>03-test-java</name>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
</dependencies>
</project>
03-test-module:
<?xml version="1.0" encoding="UTF-8"?>
<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.sm</groupId>
<artifactId>03-test-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>test</description>
<name>03-test-module</name>
<packaging>pom</packaging> <!--pom、war、jar, 默認jar-->
<modules> <!--子模塊-->
<module>03-test-web</module>
<module>03-test-web-child</module>
</modules>
<properties>
<!-- springframe 版本控制 -->
<spring.version>4.1.6.RELEASE</spring.version>
<avro.version>1.7.7</avro.version>
</properties>
<dependencyManagement> <!-- <dependencies>中的jar直接加到項目中,管理的是依賴關係(如果有父pom,子pom,則子pom中只能被動接受父類的版本);<dependencyManagement>主要管理版本,對於子類繼承同一個父類是很有用的,集中管理依賴版本不添加依賴關係,對於其中定義的版本,子pom不一定要繼承父pom所定義的版本。-->
<dependencies>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>${avro.version}</version>
<scope>compile</scope> <!--compile、test 、runtime 、provided 、system 、import, 默認compile-->
<type>jar</type> <!--默認jar-->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- springframe end -->
<!--log4j日誌包 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- JUnit單元測試工具 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<!-- aspectJ AOP 織入器 -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
<!-- jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- JSON: jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jr</groupId>
<artifactId>jackson-jr-all</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.60</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies> <!--可以和dependencyManagement同時存在-->
<dependency>
<groupId>com.suning.saltcm</groupId>
<artifactId>acm-client</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
<build>
<finalName>03-maven-test</finalName>
<pluginManagement> <!-- 效果同 dependencyManagement -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
03-test-web:
<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/maven-v4_0_0.xsd">
<parent>
<artifactId>03-test-module</artifactId>
<groupId>com.sm</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sm</groupId>
<artifactId>03-test-web</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>03-test-web Maven Webapp</name>
<dependencyManagement> <!--如果添加了跟祖父pom.xml同樣的包信息,則以當前的爲準-->
<dependencies>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.9.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<profiles> <!-- 多環境配置, maven命令選擇: mvn compile -Dmaven.test.skip=true -Ptest-->
<profile>
<id>test</id>
<properties>
<deploy.type>test</deploy.type>
</properties>
<activation>
<activeByDefault>true</activeByDefault> <!-- 默認的環境選擇-->
</activation>
</profile>
<profile>
<id>test2</id>
<properties>
<deploy.type>test2</deploy.type>
</properties>
</profile>
<profile>
<id>sit</id>
<properties>
<deploy.type>sit</deploy.type>
</properties>
</profile>
<profile>
<id>sit2</id>
<properties>
<deploy.type>sit2</deploy.type>
</properties>
</profile>
<profile>
<id>pre</id>
<properties>
<deploy.type>pre</deploy.type>
</properties>
</profile>
<profile>
<id>preyg</id>
<properties>
<deploy.type>preyg</deploy.type>
</properties>
</profile>
<profile>
<id>pst</id>
<properties>
<deploy.type>pst</deploy.type>
</properties>
</profile>
<profile>
<id>prd</id>
<properties>
<deploy.type>prd</deploy.type>
</properties>
</profile>
<profile>
<id>prdyg</id>
<properties>
<deploy.type>prdyg</deploy.type>
</properties>
</profile>
<profile>
<id>prdyfb</id>
<properties>
<deploy.type>prdyfb</deploy.type>
</properties>
</profile>
</profiles>
<build>
<filters>
<filter>src/main/resources/filter/application-${deploy.type}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<!--是否替換資源中的屬性-->
<filtering>true</filtering>
<includes>
<include>application.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>mappers/**</include>
<include>static/**</include>
<include>*.xml</include>
</includes>
</resource>
</resources>
</build>
</project>
03-test-web-child:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>03-test-web</artifactId>
<groupId>com.sm</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../03-test-web</relativePath> <!--配置父類的pom.xml-->
</parent>
<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.sm</groupId>
<artifactId>03-test-web-child</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>source</id>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>