Apache Maven

维基百科,自由的百科全书
跳转至: 导航搜索
Apache Maven
Maven logo.svg
開發者 Apache Software Foundation
穩定版本 3.0.4[1]/
2012年1月20日;14個月前 (2012-01-20)[2]
程式語言 Java
作業系統 跨平台
開發狀態 支援,開發中
類型 构建自动化
許可協議 Apache License 2.0
網站 maven.apache.org

Apache Maven,是一个软件(特别是Java软件)项目管理自动构建工具,由Apache软件基金会所提供。基于项目对象模型(缩写:POM)概念,Maven利用一个中央信息片断能管理一个项目的构建、报告和文档等步骤。曾是Jakarta项目的子项目,现为独立Apache项目。

目录

示例 [编辑]

Maven项目使用称为项目对象模型Project Object Model,POM)来配置的。

项目对象模型存储在命名为 pom.xml 的文件中。

以下是一个简单的示例:

<project>
  <!-- model version is always 4.0.0 for Maven 2.x POMs -->
  <modelVersion>4.0.0</modelVersion>
 
  <!-- project coordinates, i.e. a group of values which
       uniquely identify this project -->
 
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0</version>
 
  <!-- library dependencies -->
 
  <dependencies>
    <dependency>
 
      <!-- coordinates of the required library -->
 
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
 
      <!-- this dependency is only used for running and compiling tests -->
 
      <scope>test</scope>
 
    </dependency>
  </dependencies>
</project>

This POM only defines a unique identifier for the project (coordinates) and its dependency on the JUnit framework. However, that is already enough for building the project and running the unit tests associated with the project. Maven accomplishes this by embracing the idea of Convention over Configuration, that is, Maven provides good default values for the project's configuration. The directory structure of a normal idiomatic Maven project has the following directory entries:

Directory name Purpose
project home Contains the pom.xml and all subdirectories.
src/main/java Contains the deliverable Java sourcecode for the project.
src/main/resources Contains the deliverable resources for the project, such as property files.
src/test/java Contains the testing classes (JUnit or TestNG test cases, for example) for the project.
src/test/resources Contains resources necessary for testing.

Then the command

mvn package

will compile all the Java files, run any tests, and package the deliverable code and resources into target/my-app-1.0.jar (assuming the artifactId is my-app and the version is 1.0.)

Using Maven itself, the user provides only configuration for the project, while the configurable plug-ins do the actual work of compiling the project, cleaning target directories, running unit tests, generating API documentation and so on. In general, users should not have to write plugins themselves. Contrast this with Ant and make in which one writes imperative procedures for doing the aforementioned tasks. ㄍЎ== 概念 == yews Project Object Model 插件Plugins 生成生命周期Build lifecycles 依赖Dependencies

IDE 集成 [编辑]

历史 [编辑]

未来 [编辑]

参見 [编辑]

补充阅读 [编辑]

Available for free as PDF download or online reading: http://www.sonatype.com/documentation/books

參考資料 [编辑]

外部链接 [编辑]