您的位置:首页 > 其它

Maven基础--POM

2016-01-06 16:32 281 查看
下面就以一个POM为例:

<modelVersion>4.0.0</modelVersion>`
<!--POM即为project object model,所以modelVersion指的是maven的版本 -->
<groupId>com.k.example.maven</groupId>
<artifactId>example-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<!--项目坐标,有了这些就可以确定本项目在maven库中的存在位置
packging常用的有四种
jar:默认
war: 页面app
pom:仅是给其它模块继承
maven-plugin:作为maven的插件项目 -->

<name>example-maven</name>
<url>http://maven.apache.org</url>
<!-- 名称和下载jia包的地址 -->

<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<!-- 依赖归集 ,修改一个可完成全部修改 -->
<xxx.version>3.8.1</xxx.version>
</properties>
<!-- maven属性的定义 -->

<dependencies>
<dependency>
<!-- 依赖排除 -->
<exclusions>
<exclusion>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
</exclusion>
</exclusions>

<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${xxx.version}</version>
<scope>test</scope>
<!-- scope指定jar包的作用范围
Runtime:比如:JDBC 只有运行的时候用到
Provided:比如:Servlet-api 只有编译的时候用到
Test:比如Junit 只有调试的时候用到
complile(默认):啥时候都用到 -->
</dependency>
</dependencies>
<!-- 项目依赖
依赖具有传递性,就近性和优先定义性
依赖传递:A->B  B->C 则A->C
依赖就近:A->B->1.0   A->2.O 则取版本为2.0的
优先定义:谁先定义就采用谁的版本-->

<build>
<plugins>
<plugin>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.5.1</version>
<configuration>
<!-- 指定开发所用的jdk版本 -->
<soure>1.6</soure>
<target>1.6</target>
<showDeprecation>true</showDeprecation>
<showWarning>true</showWarning>
</configuration>
</plugin>
</plugins>
</build>
<!-- 自定义插件的使用 -->


继承介绍

父模块中的写法
<modules>
<module>子模块A的artifactId</module>
</modules>

<properties>
<xxx.version>2.0.0</xxx.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>${xxx.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 管理所有依赖的版本号,在子项目中无需再指定版本号,这里只是声明并不下载 -->

子模块中的写法
<parent>
<groupId>父模块的groupId</groupId>
<artifactId>子模块A的artifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<!-- 各个子模块的groupId是共享parent的
".."代表上级目录,被继承的父类的打包方式必须是pom;
可以继承父类中指定的版本-->

<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
</dependency>
</dependencies>
<!-- 由于版本在父模块中指定过了,所有无需再指定 -->
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  maven POM