Maven学习小结
Maven做为一个项目管理工具,通常用来构建项目,和管理项目中lib之间的依赖关系。
src/main/java | Application/Library sources |
src/main/resources | Application/Library resources |
src/main/filters | Resource filter files |
src/main/assembly | Assembly descriptors |
src/main/config | Configuration files |
src/main/scripts | Application/Library scripts |
src/main/webapp | Web application sources |
src/test/java | Test sources |
src/test/resources | Test resources |
src/test/filters | Test resource filter files |
src/site | Site |
LICENSE.txt | Project's license |
NOTICE.txt | Notices and attributions required by libraries that the project depends on |
README.txt | Project's readme |
3)Maven坐标(Coordinates)Maven定义了一组标识,来唯一标识一个项目、一个依赖或者一个插件。通过groupId, artifactId,version,packaging四元组来标识一个项目的坐标。Maven仓库(Repository)通过坐标来定位相应的构件。
4)Maven仓库(Repository)Maven仓库中存放着一些构件,根据坐标可查找到相应的构件。只有2种类型的仓库local和remote。当项目需要使用构件时,先查找local仓库,如果没有会从remote仓库上下载到local仓库。
5)依赖管理(Dependencies Management)Dependency management is one of the features of Maven that is best known to users and is one of the areas where Maven excels(擅长)。传递依赖(Transitive Dependencies)allows you to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically。
3.Maven Archetype 插件
In short, Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made。 Archetype插件共有4个目标:generate, create-from-project, crawl, create(@deprecated)。
mvn archetype:generate是根据一个原始模型,生成一个项目。
4.POM
A Project Object Model or POM is the fundamental unit of work in Maven.It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.在POM里可以指定项目的依赖,执行的插件和目标,以及项目的版本、描述、开发者、邮件列表等等。
1)Super POM
所有的Maven项目的POM都扩展自Super POM,Super POM定义了一组被所有项目共享的默认设置。Maven 3.x的Super POM在${M2_HOME}/lib/maven-model-builder-3.0.4.jar/org.apache.maven.model/pom-4.0.0.xml.部分代码
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<pluginManagement>
<!-- NOTE: These plugins will be removed from future versions of the super POM -->
<!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>