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学习
- maven插件maven-war-plugin的使用
- jenkins------部署项目到jboss eap下
- maven使用经验集
- window下安装和配置maven环境
- 使用maven+eclipse搭建struts2开发环境
- Java随手笔记8之包、环境变量和访问控制及maven profile实现多环境打包
- maven中下载jar包源码和javadoc的命令介绍
- 表单重复提交处理总结
- Maven私服配置记录 Nexus
- Maven学习笔记
- Maven实战(三)Eclipse构建Maven项目
- maven基本要点
- Maven for Eclipse
- maven 使用 问题记录
- 《Maven权威指南》学习笔记四_创建一个简单的Maven项目
- 《Maven权威指南》学习笔记五_Project Object Model(POM)
- 《Maven权威指南》学习笔记十七_一个多模块项目 3ff0
- 《Maven权威指南》学习笔记十八_多模块企业级项目 3ff0
- Docker+Jenkins+GIT+Tomcat实战持续化集成