简单的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>
<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>
<modelVersion>4.0.0</modelVersion>
表示pom支持的maven版本。目前4.0.0支持Maven2&3.必须配置
基础设置
<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>org.codehaus.mojo</groupId>
<artifactId>my-project</artifactId>
<version>1.0</version>
</project>
注释:
groupId:artifactId:version(缩写GAV)一般是必须(但是在继承父pom之后,groupId和version不用明确标识),这三个标签像坐标一样明确指定maven项目
groupId:唯一的标识,表示机构或者项目
artifactId:项目名称
version:版本号,用于描述项目的版本号。简单而言:代码发生重大模块的变更,版本号应该进行变化。
在软件的生命周期中,我们需要这3个元素指定一个项目版本让maven知道他在处理什么。
packaging: 基础标签。完善项目的类型,默认值为jar.当前值包括:pom, jar, maven-plugin, ejb, war, ear, rar, par.对于不同类型对应着项目的不同生命周期的来进行打包。如:jar 对应maven-jar-plugin. war对应maven-war-plugin.
classifier:偶尔见到的第五个标签,分类器
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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<type>jar</type>
<scope>test</scope>
<optional>true</optional>
</dependency>
...
</dependencies>
...
</project>
GA:指定依赖的坐标
V:必须指定依赖的版本号
当maven项目引用了中央库不存在或者由于是闭源许可证(不能进入中央库)导致无法从库中进行下载。下面有三种办法处理这个问题:
1)使用install插件,最简单的版本推荐使用。如:
mvn install:install-file -Dfile=non-maven-proj.jar -DgroupId=some.group -DartifactId=non-maven-proj -Dversion=1 -Dpackaging=jar
2)创建自己的版本库,这种方式在公司内部比较受欢迎,主要是大家都可以进行同步。maven命令为:deploy:deploy-file 类似于install:install-file
3)设置scope标签为system,定义一个systemPath标签。最不推荐,稍后解释
type:默认为jar,可以依据设置 extensions标签为true来控制,所以没有固定的列表
scope:这个标签参考classpath的任务执行范围(如:编译、运行时、测试等)有5个值。
compile :默认值,可以作为传播到其他的项目(继承)
provided :类似与compile,但是需要指定JDK或者容器,它只能用于编译和测试下的classpath
待续。。。。