3.pom标签详解
3.1 项目坐标标签:
- <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">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>my-project</artifactId>
- <version>1.0</version>
- <packaging>war</packaging>
- </project>
- groupId : 组织标识,例如:org.codehaus.mojo,在M2_REPO目录下,将是: org/codehaus/mojo目录。
- artifactId : 项目名称,例如:my-project,在M2_REPO目录下,将是:org/codehaus/mojo/my-project目录。
- version : 版本号,例如:1.0,在M2_REPO目录下,将是:org/codehaus/mojo/my-project/1.0目录。
- packaging : 打包的格式,可以为:pom , jar , maven-plugin , ejb , war , ear , rar , par
- modelVersion:定义pom版本号,版本号有一系列的规则
(依赖关系列表(dependency list)是POM的重要部分,也就是我们项目对jar包的管理)
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.0</version>
- <scope>test</scope>
- </dependency>
- …
- </dependencies>
- groupId , artifactId , version :引用的坐标
- scope : compile(default),provided,runtime,test,system 依赖的范围
- exclusions 需要排除的依赖的jar包
3.3 继承和聚合(子pom对父pom依赖 和 父项目对模块的依赖)
- <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">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.maven.my</groupId>
- <artifactId>${projectName}-parent</artifactId>
- <version>2.0</version>
- <!-- 定义项目有哪些子模块 -->
- <modules>
- <module>my-spring-web<module>
- <module>my-spring-service<module>
- <module>my-spring-common<module>
- <module>my-spring-dao<module>
- </modules>
- </project>
(可以帮我们指定 需要的maven插件,主要标签:Resources和Plugins
Resources:用于排除或包含某些资源文件
可以用于解决 我们部署测试和线上 服务时,资源文件配置的隔离依赖:-Ponline | -Plocal
- <build>
- <!-- 开启资源文件过滤 -->
- <resources>
- <resource>
- <directory>${project.basedir}/src/main/resources</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
- </build>
- <!-- 指定资源文件路径 -->
- <profiles>
- <!--测试配置 -->
- <profile>
- <id>local</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <build>
- <filters>
- <filter>${project.basedir}/src/main/swap/local.properties</filter>
- </filters>
- </build>
- </profile>
- <!-- 线上配置 -->
- <profile>
- <id>online</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
- <build>
- <filters>
- <filter>${project.basedir}/src/main/swap/online.properties</filter>
- </filters>
- </build>
- </profile>
Plugins:设置构建的插件
- <build>
- …
- <!-- 配置maven在运行时 需要依赖的插件,我们平常可以配jetty插件或者assemebly插件等-->
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.0</version>
- <extensions>false</extensions>
- <inherited>true</inherited>
- <configuration>
- <classifier>test</classifier>
- </configuration>
- <dependencies>…</dependencies>
- <executions>…</executions>
- </plugin>