pom作为项目对象模型,通过xml表示maven项目,使用pom.xml文件来实现。
<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>...</groupId> <!-- 项目或者组织的唯一标志,并且配置时生成的路径也是由此生成,如org.codehaus.mojo生成的相对路径为/org/codehaus/mojo --> <artifactId>...</artifactId> <!--项目的通用名称--> <version>...</version> <!--项目的版本--> <packaging>...</packaging> <!--打包的机制--> <dependencies>...</dependencies> <parent>...</parent> <dependencyManagement>...</dependencyManagement> <modules>...</modules> <properties>...</properties> <!-- 构建过程的设置 --> <build>...</build> <reporting>...</reporting> <!-- 项目信息设置 --> <name>...</name> <description>...</description> <url>...</url> <inceptionYear>...</inceptionYear> <licenses>...</licenses> <organization>...</organization> <developers>...</developers> <contributors>...</contributors> <!-- 环境设置 --> <issueManagement>...</issueManagement> <ciManagement>...</ciManagement> <mailingLists>...</mailingLists> <scm>...</scm> <prerequisites>...</prerequisites> <repositories>...</repositories> <pluginRepositories>...</pluginRepositories> <distributionManagement>...</distributionManagement> <profiles>...</profiles> </project>
pom定义了最小的maven2元素,允许groupId,artifactId,version的所有需要的元素。
pom关系:依赖,集成,合成
依赖关系:
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.0</version> <type>jar</type> <scope>test</scope> <optional>true</optional> </dependency> ... </dependencies>
继承关系
<project> <modelVersion>4.0.0</modelVersion> <groupId>org.codehaus.mojo</groupId> <artifactId>my-parent</artifactId> <version>2.0</version> <packaging>pom</packaging> </project>
合成(或者多个模块)
一个项目有多个模块,也叫做多重模块,或者合成项目。
<project> <modelVersion>4.0.0</modelVersion> <groupId>org.codehaus.mojo</groupId> <artifactId>my-parent</artifactId> <version>2.0</version> <modules> <module>my-project1<module> <module>my-project2<module> </modules> </project>
插件
在build时,执行的插件,比较有用的部分,如使用jdk6.0编译等等
<project> <build> ... <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.0</version> <!-- true或false,是否加载插件扩展,默认false--> <extensions>false</extensions> <!-- true或false,是否此插件配置会应用与pom--> <inherited>true</inherited> <!-- 指定插件配置--> <configuration> <classifier>test</classifier> </configuration> <!-- 插件需要依赖的包--> <dependencies>...</dependencies> <!-- 用于配置execution目标,一个插件可以有多个目标--> <executions>...</executions> </plugin> </plugins> </build> </project>