maven项目的结构。
一、分析
(1)Maven依赖管理
所谓依赖,就是项目想要运行,需要的那些第三方类库文件。
Maven通过坐标来管理依赖。
依赖在pom.xml文件中,在<dependencies>中进行标记,实际开发中,依赖关系是最复杂的。
我们依赖的组件自身可能也有依赖,那么我们用不用把所有的依赖都写进pom.xml文件里呢?答案是不用的,因为Maven具有传递性依赖功能:
一个复杂项目会包含很多依赖,也有可能包含其他依赖构件的依赖。你不需要找出所有的依赖然后写入pom文件里,你只需要加上你直接依赖的那些库,Maven会隐式地把这些库间接依赖的库也加入到你的项目中。
依赖的作用范围:
- compile:编译范围,默认范围,处于这个范围的依赖,在所有classpath范围里都是可用的,同时也会被打包。
- provided:已提供范围,当jdk或者容器已经提供了依赖之后才会使用。比如说你开发了一个web应用,然后你用了一个servlet-api来编译一个servlet,但是你不需要在jar文件中打包这个servlet-api,因为已经由服务器提供。这个时候你可以设为provided,只在编译的时候作用而不打包到jar文件中。
- runtime:运行时范围,运行和测试时需要,但是编译时不需要。
- test:测试范围,一般编译运行不需要,测试时才需要。
- system:系统范围,不常用,我没用过。不详细描述了。
(2)Maven仓库
- 本地仓库。
- 远程仓库。
(3)项目站点报告
Maven目标项目文件夹,shift 右键,打开命令行窗口(在当前路径打开cmd),使用
1 |
mvn site |
报告如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
D:\javaworkplace\demo>mvn site [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building demo Maven Webapp 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-site-plugin:3.3:site (default-site) @ demo --- [WARNING] Report plugin org.apache.maven.plugins:maven-project-info-reports-plug in has an empty version. [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten t he stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support buildin g such malformed projects. [INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-rep orts-plugin:2.8.1 [INFO] Relativizing decoration links with respect to project URL: http://maven.a pache.org [INFO] Rendering site with org.apache.maven.skins:maven-default-skin:jar:1.0 ski n. [INFO] Generating "Dependencies" report --- maven-project-info-reports-plugin :2.8.1 [INFO] Generating "Dependency Convergence" report --- maven-project-info-repo rts-plugin:2.8.1 [INFO] Generating "Dependency Information" report --- maven-project-info-repo rts-plugin:2.8.1 [INFO] Generating "About" report --- maven-project-info-reports-plugin:2.8.1 [INFO] Generating "Plugin Management" report --- maven-project-info-reports-p lugin:2.8.1 [INFO] Generating "Project Plugins" report --- maven-project-info-reports-plu gin:2.8.1 [INFO] Generating "Project Summary" report --- maven-project-info-reports-plu gin:2.8.1 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 13.542 s [INFO] Finished at: 2016-01-27T16:17:29+08:00 [INFO] Final Memory: 16M/42M [INFO] ------------------------------------------------------------------------ D:\javaworkplace\demo> |
然后在Maven项目文件夹-target文件夹-site文件夹下就会生成站点基本信息。
打开index.html,你就可以看见你的项目的具体实施情况了。你也可以加上一些信息,让你的测试站点更完善。
我的pom.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>test</groupId> <artifactId>demo</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>demo Maven Webapp</name> <description>这是xie的测试项目</description> <url>http://maven.apache.org</url> <organization> <name>godlikexie</name> <url>http://www.xie4ever.com.cn</url> </organization> <developers> <developer> <id>godlikexie</id> <name>xie</name> <email>503822883@qq.com</email> </developer> </developers> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.5.0-b01</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.2.4.RELEASE</version> </dependency> </dependencies> <build> <finalName>demo</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.3</version> <configuration> <locales>zh_CN</locales> </configuration> </plugin> </plugins> </build> </project> |
可以看见我加上了一些团队信息。
这段代码让网页变成中文:
1 2 3 4 5 6 7 8 9 10 |
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.3</version> <configuration> <locales>zh_CN</locales> </configuration> </plugin> </plugins> |
二、总结
一些常用的东西就在这里了。