`
bigelf
  • 浏览: 7608 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

Maven2完全使用手册(2)

阅读更多
maven 配置篇 之 pom.xml
    完了 settings.xml 配置,下来 一下 maven2 的主要配置 pom.xml
pom?

   
pom 为项 象模型。通 xml 表示maven 目,使用pom.xml来 实现 。主要描述了 目:包括配置文件; 开发 者需要遵循的 规则 ,缺陷管理系 组织 和licenses, 目的url, 目的依 性,以及其他所有的 目相 因素。
快速察看:

<project>
  <modelVersion>4.0.0</modelVersion>

  <!-- The Basics -->
  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>...</version>
  <packaging>...</packaging>
  <dependencies>...</dependencies>
  <parent>...</parent>
  <dependencyManagement>...</dependencyManagement>
  <modules>...</modules>
  <properties>...</properties>

  <!-- Build Settings -->
  <build>...</build>
  <reporting>...</reporting>

  <!-- More Project Information -->
  <name>...</name>
  <description>...</description>
  <url>...</url>
  <inceptionYear>...</inceptionYear>
  <licenses>...</licenses>
  <organization>...</organization>
  <developers>...</developers>
  <contributors>...</contributors>

  <!-- Environment Settings -->
  <issueManagement>...</issueManagement>
  <ciManagement>...</ciManagement>
  <mailingLists>...</mailingLists>
  <scm>...</scm>
  <prerequisites>...</prerequisites>
  <repositories>...</repositories>
  <pluginRepositories>...</pluginRepositories>
  <distributionManagement>...</distributionManagement>
  <profiles>...</profiles>
</project>

基本内容:
    POM
包括了所有的 目信息。
maven

pom
了最小的 maven2 元素,允 groupId,artifactId,version 。所有需要的元素
  • groupId:项目或者组织的唯一标志,并且配置时生成的路径也是由此生成,如org.codehaus.mojo生成的相对路径为:/org/codehaus/mojo
  • artifactId: 项目的通用名称
  • version:项目的版本
  • packaging: 打包的机制,如pom, jar, maven-plugin, ejb, war, ear, rar, par
  • classifier: 分类
POM 系:
主要 承,合成

 
赖关 系:
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.0</version>
      <type>jar</type>
      <scope>test</scope>
      <optional>true</optional>
    </dependency>
    ...
  </dependencies>
  • groupId, artifactId, version:描述了依赖的项目唯一标志
可以通 以下方式 行安装:
·   使用以下的命令安装:
·   mvn install:install-file –Dfile=non-maven-proj.jar –DgroupId=some.group –DartifactId=non-maven-proj –Dversion=1
·   建自己的 , 并配置,使用 deploy:deploy-file
·   置此依 围为 system ,定 一个系 路径。 不提倡。
  • type:相应的依赖产品包形式,如jar,war
  • scope:用于限制相应的依赖范围,包括以下的几种变量:
·   compile :默 ,用于 编译
·   provided 似于 编译 ,但支持你期待 jdk 或者容器提供, 似于 classpath
·   runtime: ,需要使用
·   test: 用于 test 务时 使用
·   system: 需要外在提供相 得元素。通 systemPath 来取得
  • systemPath: 仅用于范围为system。提供相应的路径
  • optional: 标注可选,当项目自身也是依赖时。用于连续依赖时使用
   独占性    
  
外在告 maven 你只包括指定的 目,不包括相 的依 。此因素主要用于解决版本冲突 问题

  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-embedder</artifactId>
      <version>2.0</version>
      <exclusions>
        <exclusion>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-core</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
表示 目maven-embedder需要 目maven-core,但我 不想引用maven-core


   
另一个 大的 化,maven 来的是 承。主要的 置:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>my-parent</artifactId>
  <version>2.0</version>
  <packaging>pom</packaging>
</project>
    packaging
型,需要pom用于parent和合成多个 目。我 需要增加相 值给 父pom,用于子 承。 主要的元素如下:
  • 依赖型
  • 开发者和合作者
  • 插件列表
  • 报表列表
  • 插件执行使用相应的匹配ids
  • 插件配置
  • 子项目配置
<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>my-parent</artifactId>
    <version>2.0</version>
    <relativePath>../my-parent</relativePath>
  </parent>
  <artifactId>my-project</artifactId>
</project>
relativePath
可以不需要,但是用于指明 parent 的目 ,用于快速 查询


dependencyManagement

用于父 目配置共同的依 赖关 系,主要配置依 包相同因素,如版本, scope

合成(或者多个模
   
一个 目有多个模 ,也叫做多重模 ,或者合成 目。
如下的定
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>my-parent</artifactId>
  <version>2.0</version>
  <modules>
    <module>my-project1<module>
    <module>my-project2<module>
  </modules>
</project>

build

   
主要用于 编译设 置,包括两个主要的元素, build report
  build
   
主要分 两部分,基本元素和 展元素集合

注意:包括 build profile build
<project>
  <!-- "Project Build" contains more elements than just the BaseBuild set -->
  <build>...</build>
  <profiles>
    <profile>
      <!-- "Profile Build" contains a subset of "Project Build"s elements -->
      <build>...</build>
    </profile>
  </profiles>
</project>

基本元素

<build>
  <defaultGoal>install</defaultGoal>
  <directory>${basedir}/target</directory>
  <finalName>${artifactId}-${version}</finalName>
  <filters>
    <filter>filters/filter1.properties</filter>
  </filters>
  ...
</build>
  • defaultGoal: 定义默认的目标或者阶段。如install
  • directory: 编译输出的目录
  • finalName: 生成最后的文件的样式
  • filter: 定义过滤,用于替换相应的属性文件,使用maven定义的属性。设置所有placehold的值

(resources)
   
目中需要指定的 源。如 spring 配置文件
,log4j.properties
<project>
  <build>
    ...
    <resources>
      <resource>
        <targetPath>META-INF/plexus</targetPath>
        <filtering>false</filtering>
        <directory>${basedir}/src/main/plexus</directory>
        <includes>
          <include>configuration.xml</include>
        </includes>
        <excludes>
          <exclude>**/*.properties</exclude>
        </excludes>
      </resource>
    </resources>
    <testResources>
      ...
    </testResources>
    ...
  </build>
</project>
  • resources: resource的列表,用于包括所有的资源
  • targetPath: 指定目标路径,用于放置资源,用于build
  • filtering: 是否替换资源中的属性placehold
  • directory: 资源所在的位置
  • includes: 样式,包括那些资源
  • excludes: 排除的资源
  • testResources: 测试资源列表
插件
 
build 行的插件,比 有用的部分,如使用 jdk 5.0 编译 等等

<project>
  <build>
    ...
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.0</version>
        <extensions>false</extensions>
        <inherited>true</inherited>
        <configuration>
          <classifier>test</classifier>
        </configuration>
        <dependencies>...</dependencies>
        <executions>...</executions>
      </plugin>
    </plugins>
  </build>
</project>
  • extensions: true or false,是否装载插件扩展。默认false
  • inherited: true or false,是否此插件配置将会应用于poms,那些继承于此的项目
  • configuration: 指定插件配置
  • dependencies: 插件需要依赖的包
  • executions: 用于配置execution目标,一个插件可以有多个目标。
如下:
    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>

        <executions>
          <execution>
            <id>echodir</id>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>verify</phase>
            <inherited>false</inherited>
            <configuration>
              <tasks>
                <echo>Build Dir: ${project.build.directory}</echo>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
 
明:
  • id:规定execution 的唯一标志
  • goals: 表示目标
  • phase: 表示阶段,目标将会在什么阶段执行
  • inherited: 和上面的元素一样,设置false maven将会拒绝执行继承给子插件
  • configuration: 表示此执行的配置属性

插件管理
    pluginManagement
:插件管理以同 的方式包括插件元素,用于在特定的 目中配置。所有 承于此 目的子 目都能使用。主要定 插件的共同元素


展元素集合
主要包括以下的元素:
Directories
用于 置各 录结 构,如下:
  <build>
    <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
    <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
    <outputDirectory>${basedir}/target/classes</outputDirectory>
    <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
    ...
  </build>

Extensions

表示需要 展的插件,必 包括 build 路径。

<project>
  <build>
    ...
    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ftp</artifactId>
        <version>1.0-alpha-3</version>
      </extension>
    </extensions>
    ...
  </build>
</project>

Reporting
   
用于在 site 表。特定的 maven 插件能 出相 的定制和配置 表。
  <reporting>
    <plugins>
      <plugin>
        <outputDirectory>${basedir}/target/site</outputDirectory>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <reportSets>
          <reportSet></reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>

Report Sets
   
用于配置不同的目 用于不同的
<reporting>
    <plugins>
      <plugin>
        ...
        <reportSets>
          <reportSet>
            <id>sunlink</id>
            <reports>
              <report>javadoc</report>
            </reports>
            <inherited>true</inherited>
            <configuration>
              <links>
                <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
              </links>
            </configuration>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>

更多的 目信息
name:
目除了 artifactId 外,可以定 多个名称
description:
目描述
url:
url
inceptionYear:
始年份


Licenses
<licenses>
  <license>
    <name>Apache 2</name>
    <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    <distribution>repo</distribution>
    <comments>A business-friendly OSS license</comments>
  </license>
</licenses>

Organization
配置 组织 信息
  <organization>
    <name>Codehaus Mojo</name>
    <url>http://mojo.codehaus.org</url>
  </organization>

Developers
配置 开发 者信息
<developers>
    <developer>
      <id>eric</id>
      <name>Eric</name>
      <email>eredmond@codehaus.org</email>
      <url>http://eric.propellors.net</url>
      <organization>Codehaus</organization>
      <organizationUrl>http://mojo.codehaus.org</organizationUrl>
      <roles>
        <role>architect</role>
        <role>developer</role>
      </roles>
      <timezone>-6</timezone>
      <properties>
        <picUrl>http://tinyurl.com/prv4t</picUrl>
      </properties>
    </developer>
  </developers>

Contributors
  <contributors>
    <contributor>
      <name>Noelle</name>
      <email>some.name@gmail.com</email>
      <url>http://noellemarie.com</url>
      <organization>Noelle Marie</organization>
      <organizationUrl>http://noellemarie.com</organizationUrl>
      <roles>
        <role>tester</role>
      </roles>
      <timezone>-5</timezone>
      <properties>
        <gtalk>some.name@gmail.com</gtalk>
      </properties>
    </contributor>
  </contributors>



Issue Management
   
bug 跟踪系 ,如 bugzilla,testtrack,clearQuest
  <issueManagement>
    <system>Bugzilla</system>
    <url>http://127.0.0.1/bugzilla</url>
  </issueManagement>
Continuous Integration Management
连续 整合管理,基于 triggers 或者 timings
  <ciManagement>
    <system>continuum</system>
    <url>http://127.0.0.1:8080/continuum</url>
    <notifiers>
      <notifier>
        <type>mail</type>
        <sendOnError>true</sendOnError>
        <sendOnFailure>true</sendOnFailure>
        <sendOnSuccess>false</sendOnSuccess>
        <sendOnWarning>false</sendOnWarning>
        <configuration><address>continuum@127.0.0.1</address></configuration>
      </notifier>
    </notifiers>
  </ciManagement>

Mailing Lists
  <mailingLists>
    <mailingList>
      <name>User List</name>
      <subscribe>user-subscribe@127.0.0.1</subscribe>
      <unsubscribe>user-unsubscribe@127.0.0.1</unsubscribe>
      <post>user@127.0.0.1</post>
      <archive>http://127.0.0.1/user/</archive>
      <otherArchives>
        <otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive>
      </otherArchives>
    </mailingList>
  </mailingLists>

SCM
 
件配置管理,如 cvs
svn
  <scm>
    <connection>scm:svn:http://127.0.0.1/svn/my-project</connection>
    <developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection>
    <tag>HEAD</tag>
    <url>http://127.0.0.1/websvn/my-project</url>
  </scm>

Repositories

配置同 setting.xml 中的 开发库


Plugin Repositories
配置同 repositories

Distribution Management
用于配置分 管理,配置相 布信息 , 主要用于 布,在 mvn deploy 后表示要 布的位置

1
配置到文件系
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>file://${basedir}/target/deploy</url>
</repository>
</distributionManagement>
2
使用 ssh2 配置
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>scp://sshserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
3
使用 sftp 配置
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>sftp://ftpserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
4
使用外在的 ssh 配置
   
编译扩 展用于指定使用 wagon 外在 ssh 提供,用于提供你的文件到相 程服 器。
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>scpexe://sshserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>1.0-alpha-6</version>
</extension>
</extensions>
</build>

5
使用 ftp 配置
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>ftp://ftpserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-alpha-6</version>
</extension>
</extensions>
</build>

repository
对应 于你的 开发库 ,用 信息通 settings.xml 中的 server 取得

Profiles
似于 settings.xml 中的 profiles ,增加了几个元素,如下的 式:
  <profiles>
    <profile>
      <id>test</id>
      <activation>...</activation>
      <build>...</build>
      <modules>...</modules>
      <repositories>...</repositories>
      <pluginRepositories>...</pluginRepositories>
      <dependencies>...</dependencies>
      <reporting>...</reporting>
      <dependencyManagement>...</dependencyManagement>
      <distributionManagement>...</distributionManagement>
    </profile>
  </profiles>
 

分享到:
评论

相关推荐

    maven2完全使用手册

    maven2完全使用手册 maven2完全使用手册 maven2完全使用手册 maven2完全使用手册

    Maven2完全使用手册

    Maven2使用全攻略,包含了maven常用的各个标签讲解,十分有用!

    maven2完全使用手册中文版(免积分).pdf

    本书主要讲述maven的使用,常见的命令,以及如何使用maven构建一个新的框架。

    maven2完全使用手册.TXT

    maven2完全使用手册 http://maven.apache.org/pom.html

    Maven 完全使用手册

    maven 最全面的介绍,包括架构、模型、配置等,最后还有快速入门教程。(项目内部文档)

    Maven完全适用手册

    Maven完全适用手册 谨慎下载。。。。。

    maven eclipse 培训教程

    Maven2使用.ppt maven2完全使用手册.docx Maven_介绍培训.pptx Maven学习指南.pdf Maven实战.doc Maven实战.pdf Maven构建并管理Flex项目入门.pdf Maven简单实用教程.docx OTNVD_WebLogicServerDevelopment_CN.pdf ...

    Maven2_资料分享

    包含:Maven2_基础教程.pdf\《Maven权威指南》-电子书下载(PDF)(中文)\maven2完全使用手册.docx\Maven3实战笔记04Maven的生命周期和插件.doc\Maven实战.pdf\Maven学习指南.pdf

    maven完全手册

    不可多得的maven中文文档,自己整理的

    Maven完全手册

    Maven完全手册 maven2 起步 相信maven1 大家都已经很熟悉了,具体maven能做什么,就不详细说了。个人觉得maven在开源项目中用的还是比较多的,公司内部,就不太清楚了。我以前的公司用过一段时间,不过后来就没有...

    Maven学习资源打包汇总

    包含以下资料: Maven权威指南 Maven2_基础教程 maven2完全使用手册 Maven3实战笔记04Maven的生命周期和插件 Maven实战 Maven学习指南

    maven 完全手册

    Maven The Complete Reference 中文版

    jfinal实例-官网

    jetty 等 web server 来启动,启动方式与非jfinal项目完全一样。 5: maven 项目还可以在控制台通过 mvn jetty:run 来启动 6: 打开浏览器输入 localhost 即可查看运行效果 注意: 请确保您安装了 JavaSE 1.6 或...

Global site tag (gtag.js) - Google Analytics