POM的实例为:
<artifactId>animation</artifactId>
<groupId>kyoto anime</groupId>
<version>1.0.5</version>
<modelVersion>4.0.0</modelVersion>
<name>ka</name>
<packaging>war<packaging>
其中modelVersion制定了当前POM模型的版本。在MAVEN2和MAVEN3中只能是4.0.0.
maven的坐标为:
- groupID:定义项目属于哪个组
- artifactID:定义当前Maven项目在这组中的唯一id
- version:定义了当前版本
packaging为打包类型,默认是jar包。
添加依赖:
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies>
此处添加了一个依赖,groupID、artifactID和version是坐标,scope为依赖范围。
此处的依赖范围是test,表示该依赖只对主代码和测试代码有效。
使用Archetype生成项目骨架
简单的运行
mvn archetype:generate
实际上是在运行插件maven-archetype-plugin。