maven初学者日记1
maven菜鸟日记1
最近看了下maven3 记录一些觉得需要记的东西 在目前的了解程度觉得自己写的都是对的 学的不多难免有些理解错误
1.maven是什么?
根据这几天看到的。
maven是一个项目构建工具。它能够让项目合理的构建。相比与ant他更智能。Maven还提供了中央类库,只要配置好项目需要的类库就可以自动下载好jar,方便控制jar的版本问题,也方便下载。它的继承和聚合能很方便的分模块。
2.maven的基本使用
下载配置神马的就不说了。
和ant 类似 不过maven读的文件是pom.xml
<?xml version="1.0" encoding="UTF-8"?> <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>com.xxx.oooo</groupId> <artifactId>teasdasdst</artifactId> <version>1.0.0-SNAPSHOT</version> <name>Oooo Parent</name> </project>
|
3.maven的基本路径
Java文件路径
Src/main/java/包
测试文件路径
Src/test/java/包
4.pom文件详解
<?xml version="1.0" encoding="UTF-8"?> <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>//POM模型版本 <groupId>com.xxx.oooo</groupId>//项目名 <artifactId>oooo-parent</artifactId>//模块名 <version>1.0.0-SNAPSHOT</version>//模块版本 <packaging>pom</packaging>//打包方式[一般不写默认为jar,pom为聚合模块] <name>Oooo Parent</name>//别名 <modules> <module>oooo-webapp</module>//聚合的模块 </modules>//聚合 <properties>//声明属性 <junit.version>4.7</junit.version> …… </properties> <developers>//开发者信息 <developer> <id>poolo</id> <name>poolo</name> <email>liuyuanbolyb@126.com</email> <url>http://lurencun.com</url> <organization>CFuture</organization> <organizationUrl>http://lurencun.com</organizationUrl> </developer> </developers> <dependencyManagement>//依赖管理器 这个标签内的内容 如果子模块不写依赖则不继承 如果没写dependencyManagement则不管如何子模块都继承 <dependencies>//依赖集 <dependency>//依赖 <groupId>junit</groupId>//组id <artifactId>junit</artifactId>//项目id <version>${junit.version}</version>//版本号[这里使用声明的属性] <scope>test</scope>//使用范围 </dependency> …… </dependencies> </dependencyManagement> <distributionManagement>//发布管理器 <repository> <id>nexus-releases</id> <name>Nexus Releases Repository.</name> <url>http://192.168.**.**:8080/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshots Repository.</name> <url>http://192.168.**.**:8080/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement> <build> //构建器 <pluginManagement>//查件管理器[同依赖管理器概念] <plugins>//查件集 <plugin>//查件 <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <url>http://192.168.**.**:8080/manager/html</url> <server>tomcat_server</server> <path>/oooo</path> </configuration> </plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>${ant.version}</version> </plugin> </plugins> </pluginManagement> </build> </project>
另:groupId、artifactId、version称为坐标 |
5.maven生命周期
Maven一共有三套生命周期
分别是:clean,default,site
Clean生命周期
Pre-clean 执行一些清理前需要完成的工作
Clean 清理上一次构建生成的文件
Post-clean 执行一些清理后需要完成的工具
Default生命周期
这个很多- -看书吧p97
Site
Pre-site 执行一些在生成项目站点之前需要完成的工作。
Site 生成项目站点文档
Post-site 执行一些在项目生成
Site-deploy 将生成的项目站点发布到服务器上
6.maven依赖库的概念
Maven是有一个中心库的概念
只需要在pom中配置好,maven在运行时就会依照pom写的内容从中心库下载需要使用到得jar包。
当然这里也可以配置服务器[让项目从服务器下载 提高下载速度 但是一般人也用不到就不说了]
7.maven聚合和继承的概念
聚合:就是把不同的模块聚合在一起
<modules> <module>oooo-webapp</module>//聚合的模块 </modules> |
聚合其他模块的模块打包方式要用pom
<packaging>pom</packaging>//打包方式[一般不写默认为jar,pom为聚合模块] |
继承:就是被聚集的模块 继承父模块
<parent> <artifactId>oooo-parent</artifactId> <groupId>com.xxx.oooo</groupId> <version>1.0.0-SNAPSHOT</version> </parent> <artifactId>oooo-system</artifactId> <packaging>war</packaging> <name>Oooo System Module</name> |
8.打包概念
<packaging>war</packaging> War为web项目概念打包 Jar为类包概念打包 Pom为聚合模块概念打包 |
2011-12-8
poolo