目录:java目录下一节: maven-内置命令
一、maven项目的目录结构
pom文件定于了一个maven项目的maven配置,一般pom文件的放在项目或者模块的根目录下。
maven的遵循约定大于配置,约定了如下的目录结构:
目录 |
目的 |
${basedir} |
存放pom.xml和所有的子目录 |
${basedir}/src/main/java |
项目的java源代码 |
${basedir}/src/main/resources |
项目的资源,比如说property文件,springmvc.xml |
${basedir}/src/test/java |
项目的测试类,比如说Junit代码 |
${basedir}/src/test/resources |
测试用的资源 |
${basedir}/src/main/scripts |
项目脚本源码的目录 |
${basedir}/src/main/webapp/WEB-INF |
web应用文件目录,web项目的信息,比如存放web.xml、本地图片、jsp视图页面 |
${basedir}/target |
打包输出目录 |
${basedir}/target/classes |
编译输出目录 |
${basedir}/target/site |
生成文档的目录,可以通过index.html查看项目的文档 |
${basedir}/target/test-classes |
测试编译输出目录 |
Test.java |
Maven只会自动运行符合该命名规则的测试类 |
~/.m2/repository |
Maven默认的本地仓库目录位置 |
二、根元素和必要配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <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.companyname.project-group</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<packaging>jar</packaging> </project>
|
project是pom文件的根元素,project下有modelVersion、groupId、artifactId、version、packaging等重要的元素。其中,groupId、artifactId、version三个元素用来定义一个项目的坐标,也就是说,一个maven仓库中,完全相同的一组groupId、artifactId、version,只能有一个项目。
- project:整个pom配置文件的根元素,所有的配置都是写在project元素里面的;
- modelVersion:指定了当前POM模型的版本,对于Maven2及Maven 3来说,它只能是4.0.0;
- groupId:这是项目组的标识。它在一个组织或者项目中通常是唯一的。
- artifactId:这是项目的标识,通常是工程的名称。它在一个项目组(group)下是唯一的。
- version:这是项目的版本号,用来区分同一个artifact的不同版本。
- packaging:这是项目产生的构件类型,即项目通过maven打包的输出文件的后缀名,包括jar、war、ear、pom等。
三、父项目和parent元素
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <parent>
<artifactId>com.companyname.project-group</artifactId> <groupId>base-project</groupId> <version>1.0.1-RELEASE</version>
<relativePath>../pom.xml</relativePath> </parent>
|
所有的pom都继承自一个父pom(Super POM)。父pom包含了一些可以被继承的默认设置,如果项目的pom中没有设置这些元素,就会使用父pom中设置。例如,Super POM中配置了默认仓库http://repo1.maven.org/maven2,这样哪怕项目的pom中没有配置仓库,也可以去这个默认仓库中去下载依赖。实际上,maven pom文件约定大于配置的原则,就是通过在Super POM中预定义了一些配置信息来实现的。
Maven使用effective pom(Super pom加上工程自己的配置)来执行相关的目标,它帮助开发者在pom.xml中做尽可能少的配置。当然,这些配置也可以被重写。
parent元素可以指定父pom。用户可以通过增加parent元素来自定义一个父pom,从而继承该pom的配置。parent元素中包含一些子元素,用来定位父项目和父项目的pom文件位置。
- parent:用于指定父项目;
- groupId:parent的子元素,父项目的groupId,用于定位父项目;
- artifactId:parent的子元素,父项目的artifactId,用于定位父项目;
- version:parent的子元素,父项目的version,用于定位父项目;
- relativePath:parent的子元素,用于定位父项目pom文件的位置。
四、项目构建需要的信息
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| <build> <sourceDirectory /> <testSourceDirectory /> <outputDirectory /> <testOutputDirectory /> <scriptSourceDirectory />
<resources> <resource> <targetPath /> <filtering /> <directory /> <includes /> <excludes /> </resource> </resources> <testResources> <testResource> <targetPath /> <filtering /> <directory /> <includes /> <excludes /> </testResource> </testResources>
<pluginManagement> <plugins> <plugin> <groupId /> <artifactId /> <version /> <extensions /> <executions> <execution> <id /> <phase /> <goals /> <inherited /> <configuration /> </execution> </executions> <dependencies> <dependency> ...... </dependency> </dependencies> <inherited /> <configuration /> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId /> <artifactId /> <version /> <extensions /> <executions> <execution> <id /> <phase /> <goals /> <inherited /> <configuration /> </execution> </executions> <dependencies> <dependency> ...... </dependency> </dependencies> <goals /> <inherited /> <configuration /> </plugin> </plugins>
<extensions> <extension> <groupId /> <artifactId /> <version /> </extension> </extensions>
<defaultGoal /> <directory /> <finalName /> <filters /> </build>
|
build标签定义了构建项目需要的信息,这部分信息对于定制化项目构建是非常重要的。这里会根据build的子元素的特点,简单地分类讲解。
1、路径管理
1 2 3 4 5 6 7 8 9 10 11 12
| <sourceDirectory /> <testSourceDirectory /> <outputDirectory /> <testOutputDirectory /> <scriptSourceDirectory />
|
路径管理定义了各种源码和编译结果的输出路径。如果遵循maven默认的路径约定,这里的几个元素是不需要配置的。这些元素包括:
- sourceDirectory:项目源码目录,定义的是相对于pom文件的相对路径;
- testSourceDirectory:项目单元测试源码目录,定义的也是是相对于pom文件的相对路径;
- outputDirectory:被编译过的应用程序class文件存放的目录,也是是相对于pom文件的相对路径;
- testOutoutDIrectory:被编译过的测试class文件存放的目录,也是是相对于pom文件的相对路径;
- scriptSourceDirectory:项目脚本源码目录,也是是相对于pom文件的相对路径。由于脚本是解释性的语言,所以该目录下的内容,会直接被拷贝到输出目录,而不需要编译。
2、资源管理
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
| <resources> <resource> <targetPath /> <filtering /> <directory /> <includes /> <excludes /> </resource> </resources> <testResources> <testResource> <targetPath /> <filtering /> <directory /> <includes /> <excludes /> </testResource> </testResources>
|
这里的元素主要是对应用程序resource资源和单元测试部分resource资源的管理,分别通过resource标签和testResource标签管理两种资源。两个标签元素可选的子元素都是一样的。子元素包括:
- targetPath:描述了资源的目标输出路径,该路径是相对于target/classes的路径;
- filtering:对文件中的参数值进行过滤,需要被过滤的文件在filter中指定;
- directory:描述打包前的资源的存放路径,这个路径是相对于pom文件所在目录的相对路径;
- includes:包含的模式列表,例如**/*.xml。只有符合条件的资源文件才会在打包的时候被放入到输出路径中;
- excludes:排除的模式列表,例如**/*.xml,符合的资源文件不会在打包的时候会被过滤掉。
3、插件管理
插件管理相关的元素有两个,包括pluginManagement和plugins。pluginManagement中有子元素plugins,它和project下的直接子元素plugins的区别是,pluginManagement主要是用来声明子项目可以引用的默认插件信息,这些插件如果只写在pluginManagement中是不会被引入的。project下的直接子元素plugins中定义的才是这个项目中真正需要被引入的插件。
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
| <pluginManagement> <plugins> <plugin> <groupId /> <artifactId /> <version /> <extensions /> <executions> <execution> <id /> <phase /> <goals /> <inherited /> <configuration /> </execution> </executions> <dependencies> ...... </dependencies> <inherited /> <configuration /> </plugin> </plugins> </pluginManagement> <plugins> ...... </plugins>
|
4、构建扩展
extensions是在此构建中使用的项目的列表,它们将被包含在运行构建的classpath中。这些项目可以启用对构建过程的扩展,并使活动的插件能够对构建生命周期进行更改。简而言之,扩展是在构建期间激活的artifacts。扩展不需要实际执行任何操作,也不包含 Mojo。因此,扩展对于指定普通插件接口的多个实现中的一个是非常好的。
1 2 3 4 5 6 7 8 9 10 11 12
| <extensions> <extension> <groupId /> <artifactId /> <version /> </extension> </extensions>
|
5、其他配置
build中还有一些配置,如下:
1 2 3 4 5 6 7 8 9 10
| <defaultGoal /> <directory /> <finalName /> <filters />
|
五、项目依赖相关信息
pom文件中通过dependencyManagement来声明依赖,通过dependencies元素来管理依赖。dependencyManagement下的子元素只有一个直接的子元素dependencice,其配置和dependencies子元素是完全一致的;而dependencies下只有一类直接的子元素:dependency。一个dependency子元素表示一个依赖项目。
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
| <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-artifact</artifactId> <version>3.8.1</version>
<type>jar</type> <classifier></classifier>
<exclusions> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> <optional>true</optional>
<scope>test</scope> <systemPath></systemPath> </dependency> </dependencies>
<dependencyManagement> <dependencies> <dependency> ...... </dependency> </dependencies> </dependencyManagement>
|
这里也是根据元素的作用,简单的对dependency的子元素做了一下分类。下面按分类来看一下dependency的子元素:
1、依赖坐标
依然是通过groupId + artifactId + version来在仓库中定位一个项目:
- groupId:parent的子元素,父项目的groupId,用于定位父项目;
- artifactId:parent的子元素,父项目的artifactId,用于定位父项目;
- version:parent的子元素,父项目的version,用于定位父项目;
2、依赖类型
这个分类主要包括两个元素,分别是依赖类型和依赖的分类器。同一个项目,即使打包成同一种类型,也可以有多个文件同时存在,因为它们的分类器可能是不同的。
- type:依赖类型,默认是jar。通常表示依赖文件的扩展名,但也有例外。一个类型可以被映射成另外一个扩展名或分类器。类型经常和使用的打包方式对应,尽管这也有例外,一些类型的例子:jar,war,ejb-client和test-jar。如果设置extensions为true,就可以在plugin里定义新的类型。
- classifier:依赖的分类器。分类器可以区分属于同一个POM,但不同构建方式的构件。分类器名被附加到文件名的版本号后面,如果想将项目构建成两个单独的JAR,分别使用Java 4和6编译器,就可以使用分类器来生成两个单独的JAR构件
3、依赖传递
依赖传递相关的子元素主要有两个,用于依赖排除的exclusions和设置依赖是否可选的optional。
- exclusions:排除该项目中的一些依赖,即本项目A依赖该dependency指示的项目B,但是不依赖项目B中依赖的这些依赖;
- optional:可选依赖,用于阻断依赖的传递性,即本项目不会依赖父项目中optional设置为true的依赖。
4、依赖范围
还有一些其他元素:
- scope:依赖范围。在项目发布过程中,帮助决定哪些构件被包括进来
- compile:默认范围,用于编译; - provided:类似于编译,但支持jdk或者容器提供,类似于classpath
- runtime: 在执行时需要使用; - systemPath: 仅用于范围为system,提供相应的路径
- test: 用于test任务时使用; - system: 需要外在提供相应的元素,通过systemPath来取得
- optional: 当项目自身被依赖时,标注依赖是否传递。用于连续依赖时使用
- systemPath:该元素为依赖规定了文件系统上的绝对路径。仅在scope设置成system时才会使用。不推荐使用这个元素。不推荐使用绝对路径,如果必须要用,推荐使用属性匹配绝对路径,例如${java.home}
六、生成文档相关的元素
1 2 3 4 5 6 7 8 9 10
| <name>project-maven</name>
<url>http://123.a.b/nsnxs</url>
<description>Description of this maven project</description>
|
备注:maven可以通过mvn site命令生成项目的相关文档。
和生成文档相关的元素,包括name,url,和description。
- name:项目名称,maven生成文档会使用项目名;
- url:项目主页的地址,maven生成文档的时候使用。
- description:项目描述。如果可以使用HTML格式进行描述的时候,不推荐使用纯文本的描述。
七、远程仓库列表
远程仓库列表的配置,包括依赖和扩展的远程仓库配置,以及插件的远程仓库配置。在本地仓库找不到的情况下,maven下载依赖、扩展和插件就是从这里配置的远程仓库中进行下载。
需要注意的是release和snapshot两者的区别。release是稳定版本,一经发布不再修改,想发布修改后的项目,只能升级项目版本再进行发布;snapshot是不稳定的,一个snapshot的版本可以不断改变。项目在开发期间一般会使用snapshot,更方便进行频繁的代码更新;一旦发布到外部,或者开发基本完成,代码迭代不再频繁,则推荐使用release。
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
| <repositories> <repository> <releases> <enabled /> <updatePolicy /> <checksumPolicy /> </releases> <snapshots> <enabled /> <updatePolicy /> <checksumPolicy /> </snapshots>
<id>nanxs-repository-proxy</id> <name>nanxs-repository-proxy</name> <url>http://192.168.1.169:9999/repository/</url> <layout>default</layout> </repository> </repositories>
<pluginRepositories> <pluginRepository> ...... </pluginRepository> </pluginRepositories>
|
八、项目分发信息相关元素
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
| <distributionManagement> <repository> <uniqueVersion /> <id>nanxs-maven2</id> <name>nanxsmaven2</name> <url>file://${basedir}/target/deploy</url> <layout /> </repository> <snapshotRepository> <uniqueVersion /> <id>nanxs-maven2</id> <name>Nanxs-maven2 Snapshot Repository</name> <url>scp://svn.baidu.com/nanxs:/usr/local/maven-snapshot</url> <layout /> </snapshotRepository> <site> <id>nanxs-site</id> <name>business api website</name> <url>scp://svn.baidu.com/nanxs:/var/www/localhost/nanxs-web</url> </site> <downloadUrl /> <relocation> <groupId /> <artifactId /> <version /> <message /> </relocation>
<status /> </distributionManagement>
|
项目分发信息的相关配置,在distributionManagement中设置。设置的内容包括:
- repository和snapshotRepository:项目产生的构建/快照构建部署的远程仓库。如果不配置snapshotRepository,快照也会部署到repository中;
- site:部署项目的网站需要的信息;
- downloadUrl:项目下载页面的URL,这是为不在仓库中的构建提供的;
- relocation:如果构件有了新的group ID和artifact ID(移到了新的位置),这里列出构件的新的信息;
- status:给出该构件在远程仓库的状态,本地项目中不能设置该元素,这是工具自动更新的。
九、报表规范
报表规范描述的是使用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
|
<reporting> <excludeDefaults /> <outputDirectory /> <plugins> <plugin> <groupId /> <artifactId /> <version />
<inherited /> <configuration /> <reportSets> <reportSet> <id /> <configuration /> <inherited /> <reports /> </reportSet> </reportSets> </plugin> </plugins> </reporting>
|
十、profile配置
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 56 57 58 59 60 61 62 63 64 65 66 67 68
| <profiles> <profile> <id /> <activation> <activeByDefault /> <jdk /> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> <property> <name>mavenVersion</name> <value>2.0.3</value> </property> <file> <exists>/usr/local/abcd/abcd-home/jobs/maven-guide-zh-to-production/workspace/ </exists> <missing>/usr/local/abcd/abcd-home/jobs/maven-guide-zh-to-production/workspace/ </missing> </file> </activation>
<build /> <repositories /> <pluginRepositories /> <dependencies /> <reporting /> <dependencyManagement /> <distributionManagement />
<reports /> <modules /> <properties /> </profile> </profiles>
|
十一、邮件列表和持续集成配置
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
| <ciManagement> <system /> <url /> <notifiers> <notifier> <type /> <sendOnError /> <sendOnFailure /> <sendOnSuccess /> <sendOnWarning /> <address /> <configuration /> </notifier> </notifiers> </ciManagement>
<mailingLists> <mailingList> <name>Demo</name> <post>nanxs@123.com</post> <subscribe>nanxs@123.com</subscribe> <unsubscribe>nanxs@123.com</unsubscribe> <archive>http:/a.b.c/nanxs/demo/dev/</archive> </mailingList> </mailingLists>
|
十二、项目的描述性信息
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| <issueManagement> <system>jira</system> <url>http://jira.baidu.com/nanxs</url> </issueManagement>
<inceptionYear />
<developers> <developer> <id>HELLO WORLD</id> <name>nanxs</name> <email>123@abc.com</email> <url /> <roles> <role>Project Manager</role> <role>Architect</role> </roles> <organization>demo</organization> <organizationUrl>http://a.b.com/nanxs</organizationUrl> <properties> <dept>No</dept> </properties> <timezone>-5</timezone> </developer> </developers>
<contributors> <contributor> <name /> <email /> <url /> <organization /> <organizationUrl /> <roles /> <timezone /> <properties /> </contributor> </contributors>
<licenses> <license> <name>Apache 2</name> <url>http://a.b.com/nanxs/LICENSE-1.0.txt</url> <distribution>repo</distribution> <comments>A business-friendly OSS license</comments> </license> </licenses>
<scm> <connection>scm:svn:http://a.b.com/nanxs</connection> <developerConnection>scm:svn:http://a.b.com/nanxs</developerConnection> <tag /> <url>http://a.b.com/nanxs</url> </scm>
<organization> <name>demo</name> <url>http://a.b.com/nanxs</url> </organization>
|
十三、其他配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <prerequisites> <maven /> </prerequisites>
<modules />
<!-格式是<name>value</name>。 --> <properties />
<reports></reports>
|
POM(Project Object Model,项目对象模型) 是 Maven 工程的基本工作单元,是一个 XML 文件,包含了项目的基本信息,用于描述项目如何构建,声明项目依赖,等等。
执行任务或目标时,Maven 会在当前目录中查找 POM。它读取 POM,获取所需的配置信息,然后执行目标。
POM 中可以指定以下配置:
- 项目依赖
- 插件
- 执行目标
- 项目构建 profile
- 项目版本
- 项目开发者列表
- 相关邮件列表信息
在创建 POM 之前,我们首先需要描述项目组 (groupId), 项目的唯一 ID。
1
| <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.companyname.project-group</groupId> <artifactId>project</artifactId> <version>1.0</version> </project>
|
所有 POM 文件都需要 project 元素和三个必需字段:groupId,artifactId,version。
1 2
| <table><thead><tr><th>节点</th><th>描述</th></tr></thead><tbody><tr><td>project</td><td>工程的根标签。</td></tr><tr><td>modelVersion</td><td>模型版本需要设置为 4.0。</td></tr><tr><td>groupId</td><td>这是工程组的标识。它在一个组织或者项目中通常是唯一的。例如,一个银行组织 com.companyname.project-group 拥有所有的和银行相关的项目。</td></tr><tr><td>artifactId</td><td>这是工程的标识。它通常是工程的名称。例如,消费者银行。groupId 和 artifactId 一起定义了 artifact 在仓库中的位置。</td></tr><tr><td>version</td><td><p>这是工程的版本号。在 artifact 的仓库中,它用来区分不同的版本。例如:</p><pre class="hljs css">com.company.bank:consumer-banking:1.0 com.company.bank:consumer-banking:1.1</pre></td></tr></tbody></table>
|
父(Super)POM
父(Super)POM 是 Maven 默认的 POM。所有的 POM 都继承自一个父 POM(无论是否显式定义了这个父 POM)。父 POM 包含了一些可以被继承的默认设置。因此,当 Maven 发现需要下载 POM 中的 依赖时,它会到 Super POM 中配置的默认仓库 http://repo1.maven.org/maven2 去下载。
Maven 使用 effective pom(Super pom 加上工程自己的配置)来执行相关的目标,它帮助开发者在 pom.xml 中做尽可能少的配置,当然这些配置可以被重写。
使用以下命令来查看 Super POM 默认配置:
接下来我们创建目录 MVN/project,在该目录下创建 pom.xml,内容如下:
4.0.0 com.companyname.project-group project 1.0
在命令控制台,进入 MVN/project 目录,执行以下命令:
1
| C:\MVN\project>mvn help:effective-pom
|
Maven 将会开始处理并显示 effective-pom。
1 2 3 4 5 6 7 8 9 10
| [INFO] Scanning for projects... Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:36 min [INFO] Finished at: 2018-09-05T11:31:28+08:00 [INFO] Final Memory: 15M/149M [INFO] ------------------------------------------------------------------------
|
Effective POM 的结果就像在控制台中显示的一样,经过继承、插值之后,使配置生效。
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| <?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 h ttp://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.companyname.project-group</groupId> <artifactId>project</artifactId> <version>1.0</version> <build> <sourceDirectory>C:\MVN\project\src\main\java</sourceDirectory> <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory> <testSourceDirectory>C:\MVN\project\src\test\java</testSourceDirectory> <outputDirectory>C:\MVN\project\target\classes</outputDirectory> <testOutputDirectory>C:\MVN\project\target\test-classes</testOutputDirectory> <resources> <resource> <mergeId>resource-0</mergeId> <directory>C:\MVN\project\src\main\resources</directory> </resource> </resources> <testResources> <testResource> <mergeId>resource-1</mergeId> <directory>C:\MVN\project\src\test\resources</directory> </testResource> </testResources> <directory>C:\MVN\project\target</directory> <finalName>project-1.0</finalName> <pluginManagement> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-2</version> </plugin> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>2.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> </plugin> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>2.0</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.4</version> </plugin> <plugin> <artifactId>maven-ear-plugin</artifactId> <version>2.3.1</version> </plugin> <plugin> <artifactId>maven-ejb-plugin</artifactId> <version>2.1</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.2</version> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>2.2</version> </plugin> <plugin> <artifactId>maven-javadoc-plugin</artifactId> <version>2.5</version> </plugin> <plugin> <artifactId>maven-plugin-plugin</artifactId> <version>2.4.3</version> </plugin> <plugin> <artifactId>maven-rar-plugin</artifactId> <version>2.2</version> </plugin> <plugin> <artifactId>maven-release-plugin</artifactId> <version>2.0-beta-8</version> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.3</version> </plugin> <plugin> <artifactId>maven-site-plugin</artifactId> <version>2.0-beta-7</version> </plugin> <plugin> <artifactId>maven-source-plugin</artifactId> <version>2.0.4</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.4.3</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1-alpha-2</version> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <artifactId>maven-help-plugin</artifactId> <version>2.1.1</version> </plugin> </plugins> </build> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Maven Repository Switchboard</name> <url>http://repo1.maven.org/maven2</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <releases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Maven Plugin Repository</name> <url>http://repo1.maven.org/maven2</url> </pluginRepository> </pluginRepositories> <reporting> <outputDirectory>C:\MVN\project\target/site</outputDirectory> </reporting> </project>
|
在上面的 pom.xml 中,你可以看到 Maven 在执行目标时需要用到的默认工程源码目录结构、输出目录、需要的插件、仓库和报表目录。
Maven 的 pom.xml 文件也不需要手工编写。
Maven 提供了大量的原型插件来创建工程,包括工程结构和 pom.xml。
POM 标签大全详解
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
| <?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.0http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <artifactId/> <groupId/> <version/> <relativePath/> </parent> <modelVersion>4.0.0</modelVersion> <groupId>asia.banseon</groupId> <artifactId>banseon-maven2</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>banseon-maven</name> <url>http://www.baidu.com/banseon</url> <description>A maven project to study maven.</description> <prerequisites> <maven/> </prerequisites> <issueManagement> <system>jira</system> <url>http://jira.baidu.com/banseon</url> </issueManagement> <ciManagement> <system/> <url/> <notifiers> <notifier> <type/> <sendOnError/> <sendOnFailure/> <sendOnSuccess/> <sendOnWarning/> <address/> <configuration/> </notifier> </notifiers> </ciManagement> <inceptionYear/> <mailingLists> <mailingList> <name>Demo</name> <post>banseon@126.com</post> <subscribe>banseon@126.com</subscribe> <unsubscribe>banseon@126.com</unsubscribe> <archive>http:/hi.baidu.com/banseon/demo/dev/</archive> </mailingList> </mailingLists> <developers> <developer> <id>HELLO WORLD</id> <name>banseon</name> <email>banseon@126.com</email> <url/> <roles> <role>Project Manager</role> <role>Architect</role> </roles> <organization>demo</organization> <organizationUrl>http://hi.baidu.com/banseon</organizationUrl> <properties> <dept>No</dept> </properties> <timezone>-5</timezone> </developer> </developers> <contributors> <contributor> <name/> <email/> <url/> <organization/> <organizationUrl/> <roles/> <timezone/> <properties/> </contributor> </contributors> <licenses> <license> <name>Apache 2</name> <url>http://www.baidu.com/banseon/LICENSE-2.0.txt</url> <distribution>repo</distribution> <comments>A business-friendly OSS license</comments> </license> </licenses> <scm> <connection>scm:svn:http://svn.baidu.com/banseon/maven/banseon/banseon-maven2-trunk(dao-trunk)</connection> <developerConnection>scm:svn:http://svn.baidu.com/banseon/maven/banseon/dao-trunk</developerConnection> <tag/> <url>http://svn.baidu.com/banseon</url> </scm> <organization> <name>demo</name> <url>http://www.baidu.com/banseon</url> </organization> <build> <sourceDirectory/> <scriptSourceDirectory/> <testSourceDirectory/> <outputDirectory/> <testOutputDirectory/> <extensions> <extension> <groupId/> <artifactId/> <version/> </extension> </extensions> <defaultGoal/> <resources> <resource> <targetPath/> <filtering/> <directory/> <includes/> <excludes/> </resource> </resources> <testResources> <testResource> <targetPath/> <filtering/> <directory/> <includes/> <excludes/> </testResource> </testResources> <directory/> <finalName/> <filters/> <pluginManagement> <plugins> <plugin> <groupId/> <artifactId/> <version/> <extensions/> <executions> <execution> <id/> <phase/> <goals/> <inherited/> <configuration/> </execution> </executions> <dependencies> <dependency>......</dependency> </dependencies> <inherited/> <configuration/> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId/> <artifactId/> <version/> <extensions/> <executions> <execution> <id/> <phase/> <goals/> <inherited/> <configuration/> </execution> </executions> <dependencies> <dependency>......</dependency> </dependencies> <goals/> <inherited/> <configuration/> </plugin> </plugins> </build> <profiles> <profile> <id/> <activation> <activeByDefault/> <jdk/> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> <property> <name>mavenVersion</name> <value>2.0.3</value> </property> <file> <exists>/usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/</exists> <missing>/usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/</missing> </file> </activation> <build> <defaultGoal/> <resources> <resource> <targetPath/> <filtering/> <directory/> <includes/> <excludes/> </resource> </resources> <testResources> <testResource> <targetPath/> <filtering/> <directory/> <includes/> <excludes/> </testResource> </testResources> <directory/> <finalName/> <filters/> <pluginManagement> <plugins> <plugin> <groupId/> <artifactId/> <version/> <extensions/> <executions> <execution> <id/> <phase/> <goals/> <inherited/> <configuration/> </execution> </executions> <dependencies> <dependency>......</dependency> </dependencies> <goals/> <inherited/> <configuration/> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId/> <artifactId/> <version/> <extensions/> <executions> <execution> <id/> <phase/> <goals/> <inherited/> <configuration/> </execution> </executions> <dependencies> <dependency>......</dependency> </dependencies> <goals/> <inherited/> <configuration/> </plugin> </plugins> </build> <modules/> <repositories> <repository> <releases> <enabled/> <updatePolicy/> <checksumPolicy/> </releases> <snapshots> <enabled/> <updatePolicy/> <checksumPolicy/> </snapshots> <id/> <name/> <url/> <layout/> </repository> </repositories> <pluginRepositories> <pluginRepository> <releases> <enabled/> <updatePolicy/> <checksumPolicy/> </releases> <snapshots> <enabled/> <updatePolicy/> <checksumPolicy/> </snapshots> <id/> <name/> <url/> <layout/> </pluginRepository> </pluginRepositories> <dependencies> <dependency>......</dependency> </dependencies> <reports/> <reporting>......</reporting> <dependencyManagement> <dependencies> <dependency>......</dependency> </dependencies> </dependencyManagement> <distributionManagement>......</distributionManagement> <properties/> </profile> </profiles> <modules/> <repositories> <repository> <releases> <enabled/> <updatePolicy/> <checksumPolicy/> </releases> <snapshots> <enabled/> <updatePolicy/> <checksumPolicy/> </snapshots> <id>banseon-repository-proxy</id> <name>banseon-repository-proxy</name> <url>http://192.168.1.169:9999/repository/</url> <layout>default</layout> </repository> </repositories> <pluginRepositories> <pluginRepository>......</pluginRepository> </pluginRepositories> <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-artifact</artifactId> <version>3.8.1</version> <type>jar</type> <classifier/>
<scope>test</scope> <systemPath/> <exclusions> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> <optional>true</optional> </dependency> </dependencies> <reports/> <reporting> <excludeDefaults/> <outputDirectory/> <plugins> <plugin> <groupId/> <artifactId/> <version/> <inherited/> <configuration/> <reportSets> <reportSet> <id/> <configuration/> <inherited/> <reports/> </reportSet> </reportSets> </plugin> </plugins> </reporting> <dependencyManagement> <dependencies> <dependency>......</dependency> </dependencies> </dependencyManagement> <distributionManagement> <repository> <uniqueVersion/> <id>banseon-maven2</id> <name>banseon maven2</name> <url>file://${basedir}/target/deploy</url> <layout/> </repository> <snapshotRepository> <uniqueVersion/> <id>banseon-maven2</id> <name>Banseon-maven2 Snapshot Repository</name> <url>scp://svn.baidu.com/banseon:/usr/local/maven-snapshot</url> <layout/> </snapshotRepository> <site> <id>banseon-site</id> <name>business api website</name> <url>scp://svn.baidu.com/banseon:/var/www/localhost/banseon-web</url> </site> <downloadUrl/> <relocation> <groupId/> <artifactId/> <version/> <message/> </relocation> <status/> </distributionManagement> <properties/> </project>
|
版权声明:本文为CSDN博主「夜雨落花」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/weixin_38569499/article/details/91456988
本文由 简悦 SimpRead 转码, 原文地址 www.runoob.com