`
阅读更多

 

see:

http://maven.apache.org/guides/

http://www.blogjava.net/zyl/archive/2006/12/30/91055.html

 

---------------

顶级标签和注释

 

 

<?xml version="1.0"?>

 

 

【xml】

xml文件的经典头部标识,指定版本和代码页

 

 

<!--
-->

 

 

【comment】

注释,可放在任意位置(但不可嵌套)

以说明xml的作用或屏蔽功能

 

 

<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">
</project>

 

【project】

工程标签,pom.xml的顶级标签

 

---------------

project二级标签

 

 

<parent>
  <groupId>org.apache.struts</groupId>
  <artifactId>struts-master</artifactId>
  <version>4</version>
</parent>

 

【project/parent】

向父目录查找pom.xml,如果找不到会导致Cannot find parent编译错误。

似乎不搜索二级以上的父pom.xml。

 

 

<modelVersion>4.0.0</modelVersion>

 

【project/modelVersion】

对应project xmlns和xsi:schemaLocation,表示pom.xml格式的版本

 

 

<groupId>org.apache.struts</groupId>

 

【project/groupId】

这个pom的唯一标识符的名字空间

 

 

<artifactId>struts-parent</artifactId>

 

【project/artifactId】

这个pom的唯一标识符

 

 

<version>1.3.10</version>

 

【project/version】

子项目的具体版本,父级不需要给出

 

 

<packaging>pom</packaging>
<packaging>war</packaging>

 

【project/packaging】

最终生成物类型,父级用pom即可

 

 

<name>Struts</name>

 

【project/name】

名称(可以带空格)

 

 

<url>http://struts.apache.org/</url>

 

【project/url】

网址(一般父级用)

 

<description>Apache Struts</description>

 

【project/description】

描述(一般父级用)

 

 

<inceptionYear>2000</inceptionYear>

     

    【project/inceptionYear】

成立年份(一般父级用)

 

 

<scm>
   <connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts1/branches/STRUTS_1_3_BRANCH</connection>
   <developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts1/branches/STRUTS_1_3_BRANCH</developerConnection>
   <url>http://svn.apache.org/viewcvs.cgi/struts/struts1/struts1/branches/STRUTS_1_3_BRANCH</url>
</scm>

 

 

    【project/scm】

当前工程目录的几个代码版本控制url,基本相同,除了协议名

 

 

<ciManagement/>

 

 

【project/ciManagement】

持续集成管理(一般父级用,可无视)

 

 

<distributionManagement>
	<site>
		<id>apache-site</id>
		<url>scp://people.apache.org/www/struts.apache.org/1.x/</url>
	</site>
</distributionManagement>

 

 

    【project/distributionManagement】

产品分发信息(一般父级用,可无视)  

 

 

<organization>
	<name>Apache Software Foundation</name>
	<url>http://www.apache.org/</url>
</organization>

 

 

【project/organization】

制作组织的信息(一般父级用,可无视)  

 

--------------------

 

project二级复数标签

 

 

<profiles>
	<profile>
		<id>apps</id>
		<activation>
			<property>
				<name>apps</name>
			</property>
		</activation>
		<modules>
			<module>apps</module>
		</modules>
	</profile>
	<profile>
		<id>itest</id>
		<activation>
			<property>
				<name>itest</name>
			</property>
		</activation>
		<modules>
			<module>integration</module>
		</modules>
	</profile>
	<profile>
		<id>assembly</id>
		<activation>
			<property>
				<name>assembly</name>
			</property>
		</activation>
		<modules>
			<module>assembly</module>
		</modules>
	</profile>
	<profile>
		<id>release</id>
		<activation>
			<property>
				<name>release</name>
			</property>
		</activation>
		<build>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-gpg-plugin</artifactId>
					<executions>
						<execution>
							<id>sign-artifacts</id>
							<phase>verify</phase>
							<goals>
								<goal>sign</goal>
							</goals>
						</execution>
					</executions>
				</plugin>
			</plugins>
		</build>
	</profile>
</profiles>

 

 

【project/profiles】

类似settings.xml的参数设置

 

 

<modules>
	<module>core</module>
	<module>el</module>
	<module>extras</module>
	<module>faces</module>
	<module>mailreader-dao</module>
	<module>scripting</module>
	<module>taglib</module>
	<module>tiles</module>
</modules>

 

 

【project/modules】

指定子目录,以获取子级的pom.xml(一般父级用)

 

 

<licenses>
	<license>
		<name>The Apache Software License, Version 2.0</name>
		<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
		<distribution>repo</distribution>
		<comments/>
	</license>
</licenses>

 

 

【project/licenses】

许可证(一般父级用,可无视)

 

 

<dependencies/>

<dependencies>
  <dependency>
	 <groupId>${pom.groupId}</groupId>
	 <artifactId>struts-taglib</artifactId>
	 <version>${pom.version}</version>
  </dependency>
  <dependency>
	 <groupId>${pom.groupId}</groupId>
	 <artifactId>struts-tiles</artifactId>
	 <version>${pom.version}</version>
  </dependency>
  <dependency>
	 <groupId>javax.servlet</groupId>
	 <artifactId>servlet-api</artifactId>
	 <version>2.3</version>
	 <scope>provided</scope>
  </dependency>
</dependencies>

 

 

【project/dependencies】

依赖,用于导入外部库或内部库到classpath。

父级pom.xml一般把dependencies写成空标签

scope默认是compile表示编译期需要

scope是provided表示编译期不需要,但运行期的JDK或容器需要把它放进classpath

scope是runtime表示编译期不需要但运行期需要

scope是test表示编译期和运行期都不需要,但测试期需要

可用于依赖平行目录的其它子工程,写法见上。

 

 

<repositories>
	<repository>
		<id>apache.snapshots</id>
		<name>Apache Maven Repository (Snapshots and Test Builds)</name>
		<url>http://people.apache.org/maven-snapshot-repository</url>
		<releases><enabled>false</enabled></releases>
		<snapshots><enabled>true</enabled></snapshots>
	</repository>
</repositories>

 

 

【project/repositories】

设置远程或本地仓库,在线下载库和Maven插件。(一般父级用)

用内部局域网的Maven仓库可以提高构建速度。

全局的仓库设置在settings.xml

默认是使用maven的中央仓库,

但有时会因为库的版本不够新导致构建失败,所以需要额外指定

see

http://maven.apache.org/guides/introduction/introduction-to-repositories.html

 

-----------------------

 

project二级大标签<build></build>

 

 

<finalName>${pom.artifactId}</finalName>

 

 

【project/build/finalName】

编译的最终名称。(一般用于子级pom.xml)

 

 

<resources>
	<!-- Include resources under src/main/java in WEB-INF/classes -->
	<resource>
		<directory>src/main/java</directory>
		<includes>
			<include>**/*.properties</include>
			<include>**/*.xml</include>
		</includes>
	</resource>
</resources>

 

 

【project/build/resources】

jar/war打包时的资源过滤和复制(默认maven过滤掉所有class文件以外的文件)

可以使用通配符。

 

 

<pluginManagement>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>2.0.2</version>
			<configuration>
				<source>1.4</source>
				<target>1.4</target>
			</configuration>
		</plugin>
		<plugin>
			<artifactId>maven-javadoc-plugin</artifactId>
			<version>2.5</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-jar-plugin</artifactId>
			<version>2.2</version>
			<configuration>
				<archive>
					<manifest>
						<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
						<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
					</manifest>
				</archive>
			</configuration>
		</plugin>
		<plugin>
			<groupId>net.sf.dtddoc</groupId>
			<artifactId>dtddoc-maven-plugin</artifactId>
			<version>1.1</version>
		</plugin>
		<plugin>
			<groupId>net.sourceforge.maven-taglib</groupId>
			<artifactId>maven-taglib-plugin</artifactId>
			<version>2.3.1</version>
			<configuration>
			  <parseHtml>true</parseHtml>
			</configuration>
		</plugin>
	</plugins>
</pluginManagement>

 

 

【project/build/pluginManagement】

构建管理插件(通常是maven的系统插件)

(一般父级用)

 

 

<plugins>

	<!-- 用于dtd文件的复制-->

	<plugin>
	   <groupId>org.apache.maven.plugins</groupId>
	   <artifactId>maven-antrun-plugin</artifactId>
	   <inherited>false</inherited>
	   <version>1.3</version>
	   <executions>
		  <execution>
			 <id>copy-dtds</id>
			 <phase>site</phase>
			 <configuration>
				<tasks>
				   <copy todir="${project.build.directory}/site/dtds"
						 failonerror="false">
					  <fileset dir="${basedir}/core/src/main/resources/org/apache/struts/resources"/>
					  <fileset dir="${basedir}/tiles/src/main/resources/org/apache/struts/resources"/>
				   </copy>
				</tasks>
			 </configuration>
			 <goals>
				<goal>run</goal>
			 </goals>
		  </execution>
	   </executions>
	</plugin>
	
	<!-- 用于tomcat的插件配置-->
	
	<plugin>
		<groupId>org.codehaus.cargo</groupId>
		<artifactId>cargo-maven2-plugin</artifactId>
		<version>0.3.1</version>
		<configuration>
		   <container>
			  <containerId>tomcat5x</containerId>
			  <home>${cargo.tomcat5x.home}</home>
			  <log>${project.build.directory}/tomcat5x.log</log>
			  <output>${project.build.directory}/tomcat5x.out</output>
		   </container>
		   <configuration>
			  <home>${project.build.directory}/tomcat5x</home>
		   </configuration>
		</configuration>
	</plugin>
	
	<!--用于web应用的插件配置-->

	<!-- Include source code under WEB-INF/src/java -->
	<plugin>
		<artifactId>maven-antrun-plugin</artifactId>
		<version>1.1</version>
		<executions>
		   <execution>
			  <id>copy-sources</id>
			  <phase>process-sources</phase>
			  <configuration>
				 <tasks>
					<copy todir="${project.build.directory}/${pom.artifactId}/WEB-INF/src/java"
						  failonerror="false">
					   <fileset dir="${basedir}/src/main/java"/>
					</copy>
				 </tasks>
			  </configuration>
			  <goals>
				 <goal>run</goal>
			  </goals>
		   </execution>
		</executions>
	</plugin>
	
</plugins>

 

 

【project/build/plugins】

构建插件参数(一般父级用)

 

 

<defaultGoal>install</defaultGoal>

 

 

【project/build/defaultGoal】

默认的mvn目标名(一般父级用)

 

--------------------

 

project二级大标签reporting

 

 

<reporting>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-project-info-reports-plugin</artifactId>
			<version>2.1</version>
		 </plugin>
		<plugin>
			<artifactId>maven-javadoc-plugin</artifactId>
			<version>2.5</version>
			<configuration>
			  <links>
				<link>http://commons.apache.org/beanutils/apidocs/</link>
				<link>http://commons.apache.org/logging/commons-logging-1.0.4/docs/apidocs/</link>
				<link>http://commons.apache.org/validator/api-1.3.1/</link>
				<link>http://java.sun.com/j2se/1.4.2/docs/api/</link>
				<link>http://java.sun.com/j2ee/1.4/docs/api/</link>
			  </links>
			</configuration>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-report-plugin</artifactId>
			<version>2.4.3</version>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-checkstyle-plugin</artifactId>
			<version>2.2</version>
			<configuration>
			  <configLocation>http://svn.apache.org/repos/asf/struts/maven/trunk/build/struts_checks.xml</configLocation>
			</configuration>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-jxr-plugin</artifactId>
			<version>2.1</version>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-pmd-plugin</artifactId>
			<version>2.4</version>
		</plugin>
		<plugin>
			<groupId>net.sf.dtddoc</groupId>
			<artifactId>dtddoc-maven-plugin</artifactId>
			<version>1.1</version>
			<configuration>
				<excludes>
					<exclude>**/web-app*</exclude>
				</excludes>
			</configuration>
		</plugin>
	</plugins>
</reporting>

 

 

【project/reporting】

用于文档化、网站化、代码检查的报告插件配置参数(一般父级用)

see:

http://maven.apache.org/ref/2.0.11/maven-reporting/index.html

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics