小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

maven

 昵稱35391513 2016-07-27

Maven Tutorial
Maven Version
Maven Website
What is a Build Tool?
Installing Maven
Maven Overview - Core Concepts
Maven vs. Ant
Maven POM Files
Super POM
Effective POM
Maven Settings File
Running Maven
Maven Directory Structure
Project Dependencies
External Dependencies
Snapshot Dependencies
Maven Repositories
Maven Build Life Cycles, Phases and Goals
Maven Build Profiles
Maven Plugins

 

Maven教程
Maven版本
Maven的網(wǎng)站
構(gòu)建工具是什么?
安裝Maven
Maven概述——核心概念
Maven和螞蟻
Maven POM文件
超級(jí)POM
有效的POM
Maven設(shè)置文件
運(yùn)行Maven
Maven的目錄結(jié)構(gòu)
項(xiàng)目依賴項(xiàng)
外部依賴關(guān)系
快照的依賴性
Maven存儲(chǔ)庫(kù)
Maven構(gòu)建生命周期、階段和目標(biāo)
Maven構(gòu)建配置文件
Maven插件     

 

   Maven is a powerful build tool for Java software projects. Actually, you can build software projects using other languages too, but Maven is developed in Java, and is thus historically used more for Java projects.

      Maven是一個(gè)強(qiáng)大的Java軟件項(xiàng)目構(gòu)建工具。事實(shí)上,你也可以使用其他語(yǔ)言構(gòu)建的軟件項(xiàng)目,MavenJava開(kāi)發(fā)的,因此歷史上用于Java項(xiàng)目。
      The purpose[A1]  of this Maven tutorial[A2]  is to make you understand how Maven works. Therefore[A3]  this tutorial focuses[A4]  on the core concepts[A5]  of Maven. Once you understand the core concepts, it is much easier to lookup[A6]  the fine detail in the Maven documentation, or search for it on the internet.

      這個(gè)Maven教程的目的是讓你理解Maven是如何工作的。因此本教程的重點(diǎn)是Maven的核心概念。一旦你理解核心概念,它更容易查找Maven的細(xì)節(jié)的文檔,或在互聯(lián)網(wǎng)上搜索它。
      Actually, the Maven developers claim[A7]  that Maven is more than just a build tool. You can read what they believe it is, in their document Philosophy[A8]  of Maven. But for now, just think of it as a build tool. You will find out what Maven really is, once you understand it and start using it.

     實(shí)際上,Maven開(kāi)發(fā)者聲稱Maven不僅僅是一個(gè)構(gòu)建工具。你可以閱讀他們相信這是什么,在他們的文檔的Maven哲學(xué)。但是現(xiàn)在,只是把它看作一個(gè)構(gòu)建工具。你會(huì)發(fā)現(xiàn)Maven是什么,一旦你理解它并開(kāi)始使用它。

     The first version of this Maven tutorial is based on Maven 3.0.5. However, this tutorial has been updated in several places since the first version of this tutorial. The updates were tested with Maven 3.3.3.

這個(gè)Maven教程的第一個(gè)版本是基于Maven 3.0.5。不過(guò),本教程已經(jīng)更新在本教程的第一個(gè)版本以來(lái)的幾個(gè)地方。的更新與Maven 3.3.3測(cè)試。

 

 

       A build tool is a tool that automates[A9]  everything related to building the software project. Building a software project typically[A10]  includes one or more of these activities:
Generating source code (if auto-generated code is used in the project).
Generating documentation from the source code.
Compiling source code.
Packaging compiled code into JAR files or ZIP files.
Installing the packaged code on a server, in a repository or somewhere else.

 

一個(gè)構(gòu)建工具是一個(gè)工具,自動(dòng)構(gòu)建軟件項(xiàng)目相關(guān)的一切。建立一個(gè)軟件項(xiàng)目通常包括一個(gè)或多個(gè)活動(dòng):
生成的源代碼(如果使用自動(dòng)生成的代碼的項(xiàng)目)。
生成文檔的源代碼。
編譯源代碼。
編譯后的代碼打包成JAR文件或ZIP文件。
安裝打包代碼在一個(gè)服務(wù)器上,在一個(gè)存儲(chǔ)庫(kù)或其他地方。

 

     Any given software project may have more activities than these needed to build the finished software. Such activities can normally be plugged into a build tool, so these activities can be automated too.

     任何軟件項(xiàng)目可能比這些活動(dòng)需要構(gòu)建完成的軟件。這些活動(dòng)通??梢圆迦胍粋€(gè)構(gòu)建工具,這些活動(dòng)也可以是自動(dòng)進(jìn)行的。

     The advantage[A11]  of automating the build process[A12]  is that you minimize[A13]  the risk of humans making errors while building the software manually. Additionally, an automated build tool is typically faster than a human performing the same steps manually.

 

     自動(dòng)化構(gòu)建過(guò)程的優(yōu)點(diǎn)是,你減少人類犯錯(cuò)誤的風(fēng)險(xiǎn),而手動(dòng)構(gòu)建的軟件。此外,一個(gè)自動(dòng)構(gòu)建工具通常是速度比人工手動(dòng)執(zhí)行相同的步驟。

 

     To install Maven on your own system (computer), go to the Maven download page and follow the instructions there. In summary, what you need to do is:
Set the JAVA_HOME environment variable to point to a valid Java SDK (e.g. Java 8).
Download and unzip Maven.
Set the M2_HOME environment variable to point to the directory you unzipped Maven to.
Set the M2 environment variable to point to M2_HOME/bin (%M2_HOME%\bin on Windows, $M2_HOME/bin on unix).
Add M2 to the PATH environment variable (%M2% on Windows, $M2 on unix).
Open a command prompt and type 'mvn -version' (without quotes) and press enter.

 

安裝Maven在您自己的系統(tǒng)(計(jì)算機(jī)),Maven下載頁(yè)面,按提示操作。總之,你需要做的是:
設(shè)置JAVA_HOME環(huán)境變量指向一個(gè)有效的Java SDK(例如Java 8)。
下載并解壓縮Maven
設(shè)置M2_HOME環(huán)境變量,使之指向您解壓的目錄Maven。
M2設(shè)置環(huán)境變量,使之指向M2_HOME / bin(% M2_HOME % \ binWindows,美元M2_HOME unix / bin)。
M2添加到PATH環(huán)境變量(% M2%Windows,美元M2unix)
打開(kāi)一個(gè)命令提示符并輸入mvn - version(沒(méi)有引號(hào))和按回車。

 

After typing in the mvn -version command you should be able to see Maven execute, and the version number of Maven written out to the command prompt.
Note: Maven uses Java when executing, so you need Java installed too (and the JAVA_HOME environment variable set as explained above). Maven 3.0.5 needs a Java version 1.5 or later. I use Maven 3.3.3 with Java 8 (u45).
I have a tutorial about installing the Java SDK in case you are not familiar with that. Remember, it has to be an SDK (Software Developer Kit), not just a JRE (Java Runtime Environment). The JRE does not contain a Java compiler. Only the SDK does.

 

后輸入mvn您應(yīng)該能夠看到Maven - version命令執(zhí)行,Maven版本號(hào)寫入命令提示符。
注意:Maven使用Java在執(zhí)行,所以你也需要安裝Java(JAVA_HOME環(huán)境變量設(shè)置為上面的解釋)。Maven 3.0.5需要一個(gè)Java版本1.5或更高版本。我使用Maven 3.3.3Java 8(u45)。
我有一個(gè)關(guān)于安裝Java SDK的教程,以防你不熟悉。記住,它必須是一個(gè)SDK(軟件開(kāi)發(fā)工具包),而不只是一個(gè)JRE(Java運(yùn)行時(shí)環(huán)境)。JRE不包含一個(gè)Java編譯器。只有SDK。

 

Maven is centered around the concept of POM files (Project Object Model). A POM file is an XML representation of project resources like source code, test code, dependencies (external JARs used) etc. The POM contains references to all of these resources. The POM file should be located in the root directory of the project it belongs to.

 

Maven是圍繞POM文件(項(xiàng)目對(duì)象模型)的概念。POM文件是一個(gè)XML表示的項(xiàng)目資源(如源代碼、測(cè)試代碼、依賴外部jar(使用)等。POM包含對(duì)所有這些資源的引用。POM文件應(yīng)該位于所屬項(xiàng)目的根目錄。

 

     Here is a diagram illustrating how Maven uses the POM file, and what the POM file primarily contains:

這是一個(gè)圖說(shuō)明如何Maven POM文件使用,POM文件主要包含:

        Overview of Maven core concepts.Maven核心概念的概述。

 

   These concepts are explained briefly below to give you an overview, and then in more detail in their own sections later in this tutorial.

   這些概念簡(jiǎn)要解釋下面給你一個(gè)概述,然后詳細(xì)的部分在本教程。

 

POM Files
    When you execute a Maven command you give Maven a POM file to execute the commands on. Maven will then execute the command on the resources described in the POM.
Build Life Cycles, Phases and Goals
    The build process in Maven is split up into build life cycles, phases and goals. A build life cycle consists of a sequence of build phases, and each build phase consists of a sequence of goals. When you run Maven you pass a command to Maven. This command is the name of a build life cycle, phase or goal. If a life cycle is requested executed, all build phases in that life cycle are executed. If a build phase is requested executed, all build phases before it in the pre-defined sequence of build phases are executed too.

 

POM文件
    當(dāng)你執(zhí)行一個(gè)Maven命令你給Maven POM文件上執(zhí)行命令。Maven將執(zhí)行命令在POM中描述的資源。
建立生命周期、階段和目標(biāo)
    Maven構(gòu)建過(guò)程分成構(gòu)建生命周期、階段和目標(biāo)。構(gòu)建生命周期由一序列構(gòu)建階段,并且每個(gè)構(gòu)建階段由一系列的目標(biāo)。當(dāng)您運(yùn)行Maven你通過(guò)Maven命令。這個(gè)命令的名字是構(gòu)建生命周期、階段或目標(biāo)。如果請(qǐng)求生命周期執(zhí)行,所有構(gòu)建階段生命周期執(zhí)行。如果一個(gè)構(gòu)建階段要求執(zhí)行,所有構(gòu)建階段之前,在構(gòu)建階段的預(yù)定義的序列執(zhí)行。

 

Dependencies and Repositories
    One of the first goals Maven executes is to check the dependencies needed by your project. Dependencies are external JAR files (Java libraries) that your project uses. If the dependencies are not found in the local Maven repository, Maven downloads them from a central Maven repository and puts them in your local repository. The local repository is just a directory on your computer's hard disk. You can specify where the local repository should be located if you want to (I do). You can also specify which remote repository to use for downloading dependencies. All this will be explained in more detail later in this tutorial.

 

依賴關(guān)系和存儲(chǔ)庫(kù)
   Maven執(zhí)行的第一個(gè)目標(biāo)是檢查您的項(xiàng)目所需的依賴項(xiàng)。依賴關(guān)系是外部JAR文件(Java庫(kù)),您的項(xiàng)目使用。如果依賴不是本地Maven資源庫(kù)中,Maven下載從中央Maven存儲(chǔ)庫(kù),并將它們?cè)谀愕谋镜卮鎯?chǔ)庫(kù)。本地存儲(chǔ)庫(kù)是一個(gè)目錄在您的計(jì)算機(jī)上的硬盤。您可以指定本地存儲(chǔ)庫(kù)應(yīng)該處的位置如果你想()。您還可以指定使用哪一個(gè)遠(yuǎn)程存儲(chǔ)庫(kù)下載依賴關(guān)系。這一切將會(huì)更詳細(xì)地解釋在本教程。

 

Build Plugins
    Build plugins are used to insert extra goals into a build phase. If you need to perform a set of actions for your project which are not covered by the standard Maven build phases and goals, you can add a plugin to the POM file. Maven has some standard plugins you can use, and you can also implement your own in Java if you need to.

 

構(gòu)建插件
   構(gòu)建插件用于插入額外的目標(biāo)變成一個(gè)構(gòu)建階段。如果您需要為您的項(xiàng)目執(zhí)行的一組操作,不受標(biāo)準(zhǔn)Maven構(gòu)建階段和目標(biāo),您可以添加一個(gè)插件POM文件。Maven有一些標(biāo)準(zhǔn)的插件可以使用,還可以在Java中實(shí)現(xiàn)自己的如果你需要。

 

Build Profiles
   Build profiles are used if you need to build your project in different ways. For instance, you may need to build your project for your local computer, for development and test. And you may need to build it for deployment on your production environment. These two builds may be different. To enable different builds you can add different build profiles to your POM files. When executing Maven you can tell which build profile to use.

 

構(gòu)建配置文件
    構(gòu)建配置文件使用如果你需要以不同的方式來(lái)構(gòu)建您的項(xiàng)目。例如,您可能需要為您的本地計(jì)算機(jī)構(gòu)建您的項(xiàng)目,開(kāi)發(fā)和測(cè)試。你可能需要構(gòu)建它部署在您的生產(chǎn)環(huán)境。這兩個(gè)版本可能會(huì)有所不同。使不同的構(gòu)建可以添加不同的構(gòu)建配置文件到你的POM文件。當(dāng)執(zhí)行Maven可以告訴構(gòu)建配置文件來(lái)使用。

 

Maven vs. Ant
    Ant is another popular build tool by Apache. If you are used to Ant and you are trying to learn Maven, you will notice a difference in the approach of the two projects.
   Ant uses an imperative approach, meaning you specify in the Ant build file what actions Ant should take. You can specify low level actions like copying files, compiling code etc. You specify the actions, and you also specify the sequence in which they are carried out. Ant has no default directory layout.
   Maven uses a more declarative approach, meaning that you specify in the Maven POM file what to build, but now how to build it. The POM file describes your project resources - not how to build it. Contrarily, an Ant file describes how to build your project. In Maven, how to build your project is predefined in the Maven Build Life Cycles, Phases and Goals.

 

Maven和螞蟻
    Apache Ant是另一個(gè)流行的構(gòu)建工具。如果你習(xí)慣于Ant,你想學(xué)習(xí)Maven,您將注意到兩個(gè)項(xiàng)目的不同方法。
    Ant使用命令式的方法,這意味著您指定的Ant構(gòu)建文件螞蟻應(yīng)該采取什么行動(dòng)。您可以指定低水平復(fù)制文件等操作,編譯代碼等您指定的動(dòng)作,你也指定的順序進(jìn)行。螞蟻沒(méi)有默認(rèn)的目錄布局。
    Maven使用更多的聲明性方法,這意味著您指定的Maven POM文件構(gòu)建什么,但現(xiàn)在如何構(gòu)建它。POM文件描述您的項(xiàng)目資源,而不是如何構(gòu)建它。相反,一個(gè)Ant文件描述如何構(gòu)建您的項(xiàng)目。在Maven,如何構(gòu)建您的項(xiàng)目是預(yù)定義的Maven構(gòu)建生命周期的階段和目標(biāo)。

 

Maven POM Files
   A Maven POM file (Project Object Model) is an XML file that describe the resources of the project. This includes the directories where the source code, test source etc. is located in, what external dependencies (JAR files) your projects has etc.
The POM file describes what to build, but most often not how to build it. How to build it is up to the Maven build phases and goals. You can insert custom actions (goals) into the Maven build phase if you need to, though.
   Each project has a POM file. The POM file is named pom.xml and should be located in the root directory of your project. A project divided into subprojects will typically have one POM file for the parent project, and one POM file for each subproject. This structure allows both the total project to be built in one step, or any of the subprojects to be built separately.

 

Maven POM文件
   一個(gè)Maven POM文件(項(xiàng)目對(duì)象模型)是一個(gè)XML文件,描述項(xiàng)目的資源。這包括源代碼的目錄、測(cè)試等位于來(lái)源,外部依賴(JAR文件)項(xiàng)目等。
POM文件描述了如何構(gòu)建,但通常不是如何構(gòu)建它。如何構(gòu)建由Maven構(gòu)建階段和目標(biāo)。你可以插入自定義動(dòng)作(目標(biāo))Maven構(gòu)建階段,如果你需要。
   每個(gè)項(xiàng)目的POM文件。名為POMPOM文件。xml和應(yīng)位于您的項(xiàng)目的根目錄。一個(gè)項(xiàng)目分成子項(xiàng)目通常會(huì)有一個(gè)父項(xiàng)目的POM文件,每個(gè)子項(xiàng)目和一個(gè)POM文件。這個(gè)結(jié)構(gòu)允許的項(xiàng)目總建在一個(gè)步驟中,或任何的子項(xiàng)目分別建成。

 

Throughout the rest of this section I will describe the most important parts of the POM file. For a full reference of the POM file, see the Maven POM Reference.

在本節(jié)的其余部分,我將描述POM文件的最重要的部分。完整的POM文件的參考,請(qǐng)參閱Maven POM參考。

 

Here is a minimal POM file:這是一個(gè)最小的POM文件:


<project xmlns="http://maven./POM/4.0.0"
xmlns:xsi="http://www./2001/XMLSchema-instance"
xsi:schemaLocation="http://maven./POM/4.0.0
http://maven./xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.jenkov</groupId>
<artifactId>java-web-crawler</artifactId>
<version>1.0.0</version>
</project>


       The modelVersion element sets what version of the POM model you are using. Use the one matching the Maven version you are using. Version 4.0.0 matches Maven version 2 and 3.

modelVersion元素集您使用的是什么版本的POM模型。使用一個(gè)匹配您正在使用Maven版本。版本4.0.0匹配Maven版本23

 

   The groupId element is a unique ID for an organization, or a project (an open source project, for instance). Most often you will use a group ID which is similar to the root Java package name of the project. For instance, for my Java Web Crawler project I may choose the group ID com.jenkov. If the project was an open source project with many independent contributors, perhaps it would make more sense to use a group ID related to the project than an a group ID related to my company. Thus, com.javawebcrawler could be used.
    The group ID does not have to be a Java package name, and does not need to use the . notation (dot notation) for separating words in the ID. But, if you do, the project will be located in the Maven repository under a directory structure matching the group ID. Each . is replaced with a directory separator, and each word thus represents a directory. The group ID com.jenkov would then be located in a directory calledMAVEN_REPO/com/jenkov. The MAVEN_REPO part of the directory name will be replaced with the directory path of the Maven repository.


   組織的groupId元素是一個(gè)惟一的ID,或者一個(gè)項(xiàng)目(一個(gè)開(kāi)源項(xiàng)目,例如)。通常您將使用一組ID,類似于根項(xiàng)目的Java包名稱。例如,我可以選擇我的Java Web爬蟲項(xiàng)目com.jenkov的組ID。如果項(xiàng)目是一個(gè)開(kāi)放源碼項(xiàng)目,許多獨(dú)立的貢獻(xiàn)者,也許更有意義使用組ID相關(guān)的項(xiàng)目與我公司相關(guān)的組ID。因此,com??梢允褂?span lang="EN-US">javawebcrawler
   ID并不需要一個(gè)Java包名稱,并且不需要使用。符號(hào)(點(diǎn)符號(hào))分隔單詞的ID。但是,如果你這樣做,這個(gè)項(xiàng)目將位于Maven存儲(chǔ)庫(kù)組ID相匹配的目錄結(jié)構(gòu)中。。被替換為一個(gè)目錄分隔符,因此每個(gè)單詞代表一個(gè)目錄。com的組ID。jenkov將位于一個(gè)目錄calledMAVEN_REPO /com/jenkov。MAVEN_REPO目錄名稱的一部分將會(huì)取代Maven存儲(chǔ)庫(kù)的目錄路徑。

 

   The artifactId element contains the name of the project you are building. In the case of my Java Web Crawler project, the artifact ID would be java-web-crawler. The artifact ID is used as name for a subdirectory under the group ID directory in the Maven repository. The artifact ID is also used as part of the name of the JAR file produced when building the project. The output of the build process, the build result that is, is called an artifact in Maven. Most often it is a JAR, WAR or EAR file, but it could also be something else.
   The versionId element contains the version number of the project. If your project has been released in different versions, for instance an open source API, then it is useful to version the builds. That way users of your project can refer to a specific version of your project. The version number is used as a name for a subdirectory under the artifact ID directory. The version number is also used as part of the name of the artifact built.


   artifactId元素包含您正在構(gòu)建的項(xiàng)目的名稱。在我的Java Web爬蟲項(xiàng)目的情況下,java-web-crawler工件ID。工件ID作為名稱的組ID目錄下的子目錄Maven存儲(chǔ)庫(kù)。工件ID也作為名字的一部分構(gòu)建項(xiàng)目時(shí)產(chǎn)生的JAR文件。構(gòu)建過(guò)程的輸出,構(gòu)建結(jié)果,被稱為一個(gè)工件在Maven。通常是一個(gè)JARWAREAR文件,但它也可以是其他的東西。
   versionId元素包含項(xiàng)目的版本號(hào)。如果你的項(xiàng)目已經(jīng)發(fā)布在不同的版本中,例如一個(gè)開(kāi)源API,然后是有用的構(gòu)建版本。這樣你的項(xiàng)目的用戶可以參考您的項(xiàng)目的一個(gè)特定的版本。版本號(hào)是用作工件ID目錄下的子目錄的名稱。版本號(hào)也被用作工件的名稱的一部分。

 

   The above groupId, artifactId and version elements would result in a JAR file being built and put into the local Maven repository at the following path (directory and file name):
MAVEN_REPO/com/jenkov/java-web-crawler/1.0.0/java-web-crawler-1.0.0.jar
If your project uses the Maven directory structure, and your project has no external dependencies, then the above minimal POM file is all you need to build your project.
   If your project does not follow the standard directory structure, has external dependencies, or need special actions during building, you will need to add more elements to the POM file. These elements are listed in the Maven POM reference (see link above).
In general you can specify a lot of things in the POM which gives Maven more details about how to build your projects. See the Maven POM reference for more information about what can be specified.

 

上面的groupId,artifactId和版本元素會(huì)導(dǎo)致在建一個(gè)JAR文件放入本地Maven存儲(chǔ)庫(kù)在以下路徑(目錄和文件名稱):
MAVEN_REPO /com/jenkov/java-web-crawler/1.0.0/java-web-crawler-1.0.0.jar
   如果您的項(xiàng)目使用Maven的目錄結(jié)構(gòu),和您的項(xiàng)目沒(méi)有外部依賴,那么上述最小POM文件都是需要構(gòu)建您的項(xiàng)目。
   如果你的項(xiàng)目不遵循標(biāo)準(zhǔn)的目錄結(jié)構(gòu),外部依賴,或需要特殊的動(dòng)作在建設(shè)期間,您需要添加更多的元素POM文件。這些元素中列出的Maven POM參考(見(jiàn)上面的鏈接)
一般來(lái)說(shuō)您可以指定一個(gè)Maven POM中很多東西給更多的細(xì)節(jié)關(guān)于如何構(gòu)建您的項(xiàng)目。有關(guān)更多信息,請(qǐng)參見(jiàn)Maven POM引用可以指定。

 

Super POM
   All Maven POM files inherit from a super POM. If no super POM is specified, the POM file inherits from the base POM. Here is a diagram illustrating that:

超級(jí)POM
       所有Maven POM文件從一個(gè)超級(jí)POM繼承。如果沒(méi)有指定超級(jí)POM,POM文件繼承了POM的基地。這是一個(gè)圖說(shuō)明:

 

     Super POM and POM inheritance.超級(jí)POMPOM繼承。

 

You can make a POM file explicitly[A14]  inherit[A15]  from another POM file. That way you can change the settings across all inheriting POM's via their common super POM. You specify the super POM at the top of a POM file like this:

你可以做一個(gè)POM文件明確繼承另一個(gè)POM文件。這樣你可以更改設(shè)置在所有繼承通過(guò)他們共同的超級(jí)POM POM的。您指定超級(jí)POM POM文件的頂部是這樣的:

<project xmlns="http://maven./POM/4.0.0"
         xmlns:xsi="http://www./2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven./POM/4.0.0
                      http://maven./xsd/maven-4.0.0.xsd">
    <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>

 

An inheriting POM file may override settings from a super POM. Just specify new settings in the inheriting POM file.
POM inheritance is also covered in more detail in the Maven POM reference.

 

一個(gè)繼承POM文件可能覆蓋從超級(jí)POM設(shè)置。只是在繼承POM文件中指定新設(shè)置。
POM的繼承也詳細(xì)介紹Maven POM參考。

 

Effective POM
    With all this POM inheritance it may be hard to know what the total POM file looks like when Maven executes. The total POM file (result of all inheritance) is called the effective POM. You can get Maven to show you the effective POM using this command:
mvn help:effective-pom
This command will make Maven write out the effective POM to the command line prompt.

 

有效的POM
   所有這些POM繼承它可能很難知道總Maven POM文件的樣子時(shí)執(zhí)行??偟?span lang="EN-US">POM文件(繼承)的結(jié)果稱為有效砰的一聲。你可以得到Maven向你們展示有效的POM使用這個(gè)命令:
mvn幫助:effective-pom
這個(gè)命令將Maven POM寫出有效命令行提示符。

 

Maven Settings File
    Maven has two settings files. In the settings files you can configure settings for Maven across all Maven POM files. For instance, you can configure:
Location of local repository
Active build profile
Etc.
   The settings files are called settings.xml. The two settings files are located at:
The Maven installation directory: $M2_HOME/conf/settings.xml
   The user's home directory: ${user.home}/.m2/settings.xml
Both files are optional. If both files are present, the values in the user home settings file overrides the values in the Maven installation settings file.
You can read more about the Maven settings files in the Maven Settings Reference.

 

Maven設(shè)置文件
   Maven文件有兩個(gè)設(shè)置。在設(shè)置文件中您可以配置設(shè)置Maven所有Maven POM文件。例如,您可以配置:
本地存儲(chǔ)庫(kù)的位置
積極構(gòu)建配置文件
等。
被稱為settings.xml設(shè)置文件。這兩個(gè)設(shè)置文件位于:
   Maven安裝目錄:$ M2_HOME / conf / settings.xml
用戶的主目錄:$ { user.home } / .m2 / settings.xml
兩個(gè)文件是可選的。如果文件存在,則在用戶家里的值設(shè)置文件覆蓋Maven安裝設(shè)置文件中的值。
你可以閱讀更多關(guān)于Maven設(shè)置Maven中的文件設(shè)置參考。

 

Running Maven
    When you have installed Maven and have created a POM file and put the POM file in the root directory of your project, you can run Maven on your project.
Running Maven is done by executing the mvn command from a command prompt. When executing the mvncommand you pass the name of a build life cycle, phase or goal to it, which Maven then executes. Here is an example:
 mvn install
     This command executes the build phase called install (part of the default build life cycle), which builds the project and copies the packaged JAR file into the local Maven repository. Actually, this command executes all build phases before install in the build phase sequence, before executing the install build phase.
You can execute multiple build life cycles or phases by passing more than one argument to the mvncommand. Here is an example:
mvn clean install
    This command first executes the clean build life cycle, which removes compiled classes from the Maven output directory, and then it executes the install build phase.
You can also execute a Maven goal (a subpart of a build phase) by passing the build phase and goal name concatenated with a : in between, as parameter to the Maven command. Here is an example:
mvn dependency:copy-dependencies
This command executes the copy-dependencies goal of the dependency build phase.


運(yùn)行Maven
    當(dāng)你安裝了Maven和創(chuàng)造了一個(gè)POM文件,POM文件在您的項(xiàng)目的根目錄,您可以運(yùn)行Maven項(xiàng)目。
運(yùn)行Maven是通過(guò)執(zhí)行mvn命令從命令提示符。當(dāng)執(zhí)行mvncommand你通過(guò)構(gòu)建生命周期的名字,階段或目標(biāo),Maven然后執(zhí)行。這是一個(gè)例子:
mvn install
    這個(gè)命令執(zhí)行構(gòu)建階段稱為安裝(默認(rèn)構(gòu)建生命周期的一部分),構(gòu)建項(xiàng)目,打包的JAR文件復(fù)制到本地Maven存儲(chǔ)庫(kù)。實(shí)際上,這個(gè)命令執(zhí)行所有構(gòu)建階段在構(gòu)建階段的順序安裝之前,在執(zhí)行之前安裝構(gòu)建階段。
您可以執(zhí)行多個(gè)構(gòu)建生命周期或階段mvncommand通過(guò)傳遞多個(gè)參數(shù)。這是一個(gè)例子:
mvn全新安裝
     這個(gè)命令首先執(zhí)行清潔建造生命周期,Maven輸出目錄中刪除已編譯類,然后執(zhí)行安裝構(gòu)建階段。
您還可以執(zhí)行一個(gè)Maven目標(biāo)(一個(gè)構(gòu)建階段的組成部分)通過(guò)構(gòu)建階段和目標(biāo)連接名稱:,Maven命令的參數(shù)。這是一個(gè)例子:
mvn dependency:copy-dependencies
這個(gè)命令執(zhí)行的copy-dependencies目標(biāo)構(gòu)建階段的依賴。

 

Running Maven
   When you have installed Maven and have created a POM file and put the POM file in the root directory of your project, you can run Maven on your project.
Running Maven is done by executing the mvn command from a command prompt. When executing the mvncommand you pass the name of a build life cycle, phase or goal to it, which Maven then executes. Here is an example:
Maven Directory Structure
   Maven has a standard directory structure. If you follow that directory structure for your project, you do not need to specify the directories of your source code, test code etc. in your POM file.
You can see the full directory layout in the Introduction to the Maven Standard Directory Layout.
Here are the most important directories:

 

運(yùn)行Maven
   當(dāng)你安裝了Maven和創(chuàng)造了一個(gè)POM文件,POM文件在您的項(xiàng)目的根目錄,您可以運(yùn)行Maven項(xiàng)目。
運(yùn)行Maven是通過(guò)執(zhí)行mvn命令從命令提示符。當(dāng)執(zhí)行mvncommand你通過(guò)構(gòu)建生命周期的名字,階段或目標(biāo),Maven然后執(zhí)行。這是一個(gè)例子:
Maven的目錄結(jié)構(gòu)
   Maven標(biāo)準(zhǔn)目錄結(jié)構(gòu)。如果你遵循你的項(xiàng)目目錄結(jié)構(gòu),您不需要指定源代碼的目錄,POM文件測(cè)試代碼等。
你可以看到完整的目錄布局在Maven標(biāo)準(zhǔn)目錄布局。
這里有最重要的目錄:

- src
  - main
    - java
    - resources
    - webapp
  - test
    - java
    - resources
- target

 

The src directory is the root directory of your source code and test code. The main directory is the root directory for source code related to the application itself (not test code). The test directory contains the test source code. The java directories under main and test contains the Java code for the application itself (under main) and the Java code for the tests (under test).
The resources directory contains other resources needed by your project. This could be property files used for internationalization of an application, or something else.
   The webapp directory contains your Java web application, if your project is a web application. The webappdirectory will then be the root directory of the web application. Thus the webapp directory contains the WEB-INF directory etc.
The target directory is created by Maven. It contains all the compiled classes, JAR files etc. produced by Maven. When executing the clean build phase, it is the target directory which is cleaned.

 

src目錄是根目錄的源代碼和測(cè)試代碼。源代碼的主要目錄是根目錄與應(yīng)用程序本身(而不是測(cè)試代碼)。測(cè)試目錄包含測(cè)試源代碼。java目錄下主要包含java代碼和測(cè)試應(yīng)用程序本身(主要)java代碼的測(cè)試(測(cè)試)
   資源目錄包含項(xiàng)目所需的其他資源。這可能是屬性文件用于應(yīng)用程序的國(guó)際化,或者其他東西。
webapp目錄包含您的Java web應(yīng)用程序,如果你的項(xiàng)目是一個(gè)web應(yīng)用程序。webappdirectoryweb應(yīng)用程序的根目錄。因此,webapp目錄包含web - inf目錄等。
目標(biāo)目錄是由Maven。它包含所有已編譯類的JAR文件等由Maven。當(dāng)執(zhí)行清潔的構(gòu)建階段,清洗的目標(biāo)目錄。

 

Project Dependencies
   Unless your project is small, your project may need external Java APIs or frameworks which are packaged in their own JAR files. These JAR files are needed on the classpath when you compile your project code.
   Keeping your project up-to-date with the correct versions of these external JAR files can be a comprehensive task. Each external JAR may again also need other external JAR files etc. Downloading all these external dependencies (JAR files) recursively and making sure that the right versions are downloaded is cumbersome. Especially when your project grows big, and you get more and more external dependencies.
   Luckily, Maven has built-in dependency management. You specify in the POM file what external libraries your project depends on, and which version, and then Maven downloads them for you and puts them in your local Maven repository. If any of these external libraries need other libraries, then these other libraries are also downloaded into your local Maven repository.
   You specify your project dependencies inside the dependencies element in the POM file. Here is an example:

 

項(xiàng)目依賴項(xiàng)
    除非你的項(xiàng)目很小,您的項(xiàng)目可能需要外部Java api或框架打包的JAR文件。這些JAR文件需要在類路徑中當(dāng)你編譯您的項(xiàng)目的代碼。
保持您的項(xiàng)目與這些外部JAR文件的正確版本最新的可以是一個(gè)綜合的任務(wù)。每個(gè)外部JAR可能還需要再下載其他外部JAR文件等等。所有這些外部依賴(JAR文件)遞歸和確保正確的版本下載很麻煩。特別是當(dāng)你的項(xiàng)目越來(lái)越大,得到越來(lái)越多的外部依賴。
    幸運(yùn)的是,Maven內(nèi)置的依賴關(guān)系管理。您指定的POM文件外部庫(kù)項(xiàng)目取決于什么,哪個(gè)版本,然后Maven下載給你,并在本地Maven資源庫(kù)中。如果這些外部庫(kù)需要其他的庫(kù),那么這些其他圖書館也下載到本地Maven資源庫(kù)中。
您指定您的項(xiàng)目依賴內(nèi)部元素POM文件的依賴關(guān)系。這是一個(gè)例子:

<project xmlns="http://maven./POM/4.0.0"
         xmlns:xsi="http://www./2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven./POM/4.0.0
   http://maven./xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>com.jenkov.crawler</groupId>
    <artifactId>java-web-crawler</artifactId>
    <version>1.0.0</version>
    
      <dependencies>
 
        <dependency>
          <groupId>org.jsoup</groupId>
          <artifactId>jsoup</artifactId>
          <version>1.7.1</version>
        </dependency>
 
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    <build>
    </build>
</project>

 

Notice the dependencies element in bold. Inside it are two dependency elements. Each dependency element describes an external dependency.
Each dependency is described by its groupId, artifactId and version. You may remember that this is also how you identified your own project in the beginning of the POM file. The example above needs theorg.jsoup group's jsoup artifact in version 1.7.1, and the junit group's junit artifact in version 4.8.1.
   When this POM file is executed by Maven, the two dependencies will be downloaded from a central Maven repository and put into your local Maven repository. If the dependencies are already found in your local repository, Maven will not download them. Only if the dependencies are missing will they be downloaded into your local repository.
    Sometimes a given dependency is not available in the central Maven repository. You can then download the dependency yourself and put it into your local Maven repository. Remember to put it into a subdirectory structure matching the groupId, artifactId and version. Replace all dots (.) with / and separate the groupId, artifactId and version with / too. Then you have your subdirectory structure.
   The two dependencies downloaded by the example above will be put into the following subdirectories:

MAVEN_REPOSITORY_ROOT/junit/junit/4.8.1
MAVEN_REPOSITORY_ROOT/org/jsoup/jsoup/1.7.1

 

請(qǐng)注意元素大膽的依賴關(guān)系。里面有兩個(gè)元素的依賴。每個(gè)依賴元素描述外部依賴。
    每個(gè)依賴描述groupId,artifactId和版本。你可能還記得,這是你如何確定自己的項(xiàng)目在POM文件的開(kāi)始。上面的示例需要theorg。jsoup集團(tuán)jsoup工件在版本1.7.1,junit集團(tuán)在4.8.1版本的junit工件。
當(dāng)這個(gè)執(zhí)行的Maven POM文件,這兩個(gè)依賴項(xiàng)將從一個(gè)中央Maven存儲(chǔ)庫(kù)下載到本地Maven資源庫(kù)中。如果依賴已經(jīng)發(fā)現(xiàn)在你的本地存儲(chǔ)庫(kù),Maven不會(huì)下載它們。只有缺少的依賴關(guān)系會(huì)被下載到你的本地存儲(chǔ)庫(kù)。
    有時(shí)一個(gè)給定的依賴不是中央Maven存儲(chǔ)庫(kù)中可用。然后您可以依賴自己,把它下載到本地Maven資源庫(kù)中。記得把它放到一個(gè)子目錄結(jié)構(gòu)匹配的groupId,artifactId和版本。替換所有點(diǎn)(.)/和單獨(dú)的groupId / artifactId和版本。然后你的子目錄結(jié)構(gòu)。
上面的兩個(gè)附件下載的示例將放在以下目錄:
MAVEN_REPOSITORY_ROOT / junit junit / 4.8.1
MAVEN_REPOSITORY_ROOT /org/jsoup/jsoup/1.7.1

 

External Dependencies
     An external dependency in Maven is a dependency (JAR file) which is not located in a Maven repository (neiterh local, central or remote repository). It may be located somewhere on your local hard disk, for instance in the lib directory of a webapp, or somewhere else. The word "external" thus means external to the Maven repository system - not just external to the project. Most dependencies are external to the project, but few are external to the repository system (not located in a repository).
You configure an external dependency like this:

 

外部依賴關(guān)系
   外部依賴關(guān)系在Maven的依賴項(xiàng)(JAR文件)不是位于Maven存儲(chǔ)庫(kù)(neiterh地方、中央或遠(yuǎn)程存儲(chǔ)庫(kù))。它可能位于本地硬盤上的某個(gè)地方,例如webapplib目錄,或其他地方。外部一詞因此意味著外部到Maven存儲(chǔ)庫(kù)系統(tǒng)——不僅僅是外部的項(xiàng)目。大多數(shù)依賴外部的項(xiàng)目,但很少有外部存儲(chǔ)庫(kù)系統(tǒng)(而不是位于存儲(chǔ)庫(kù))。
你配置一個(gè)外部依賴關(guān)系是這樣的:

<dependency>
  <groupId>mydependency</groupId>
  <artifactId>mydependency</artifactId>
  <scope>system</scope>
  <version>1.0</version>
  <systemPath>${basedir}\war\WEB-INF\lib\mydependency.jar</systemPath>
</dependency>

 

      The groupId and artifactId are both set to the name of the dependency. The name of the API used, that is. The scope element value is set to system. The systemPath element is set to point to the location of the JAR file containing the dependency. The ${basedir} points to the directory where the POM is located. The rest of the path is relative from that directory.

 

groupIdartifactId都將依賴項(xiàng)的名稱。API使用的名稱。元素值設(shè)置為系統(tǒng)范圍。systemPath元素設(shè)置為指向包含依賴JAR文件的位置。$ { basedir }指向POM所在的目錄。其余的從該目錄路徑是相對(duì)的。

 

Snapshot Dependencies
     Snapshot dependencies are dependencies (JAR files) which are under development. Instead of constantly updating the version numbers to get the latest version, you can depend on a snapshot version of the project. Snapshot versions are always downloaded into your local repository for every build, even if a matching snapshot version is already located in your local repository. Always downloading the snapshot dependencies assures that you always have the latest version in your local repository, for every build.
    You can tell Maven that your project is a snapshot version simply by appending -SNAPSHOT to the version number in the beginning of the POM (where you also set the groupId and artifactId). Here is a versionelement example:

 

快照的依賴性.
    快照依賴關(guān)系正在開(kāi)發(fā)的依賴項(xiàng)(JAR文件)。而不是不斷更新最新版本的版本號(hào),你可以依靠一個(gè)快照版本的項(xiàng)目??煺瞻姹究偸菫槊恳粋€(gè)構(gòu)建下載到你的本地存儲(chǔ)庫(kù),即使一個(gè)匹配的快照版本已經(jīng)位于您的本地存儲(chǔ)庫(kù)中??偸窍螺d依賴快照確保你總是有最新版本在你的本地存儲(chǔ)庫(kù),為每一個(gè)構(gòu)建。
   你可以告訴Maven項(xiàng)目是一個(gè)快照版本只需添加版本號(hào)的快照POM的開(kāi)始(你也設(shè)置groupIdartifactId)。這是一個(gè)versionelement的例子:

<version>1.0-SNAPSHOT</version>

 

Notice the -SNAPSHOT appended to the version number.
   Depending on a snapshot version is also done by appending the -SNAPSHOT after the version number when configuring dependencies. Here is an example:


注意到快照添加到版本號(hào)。
根據(jù)快照版本也由附加后的快照版本號(hào)在配置依賴關(guān)系。這是一個(gè)例子:

<dependency>
    <groupId>com.jenkov</groupId>
    <artifactId>java-web-crawler</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

 

The -SNAPSHOT appended to the version number tells Maven that this is a snapshot version.
You can configure how often Maven shall download snapshot dependencies in the Maven Settings File.

 

快照添加到版本號(hào)告訴Maven版本,這是一個(gè)快照。
您可以配置Maven多久下載快照在Maven依賴設(shè)置文件。

 

Maven Repositories
   Maven repositories are directories of packaged JAR files with extra meta data. The meta data are POM files describing the projects each packaged JAR file belongs to, including what external dependencies each packaged JAR has. It is this meta data that enables Maven to download dependencies of your dependencies recursively, until the whole tree of dependencies is download and put into your local repository.
   Maven repositories are covered in more detail in the Maven Introduction to Repositories, but here is a quick overview.
Maven has three types of repository:
Local repository
Central repository
Remote repository
  Maven searches these repositories for dependencies in the above sequence. First in the local repository, then in the central repository, and third in remote repositories if specified in the POM.


Maven存儲(chǔ)庫(kù)
   Maven存儲(chǔ)庫(kù)目錄打包的JAR文件的額外的元數(shù)據(jù)。元數(shù)據(jù)是描述項(xiàng)目的POM文件每個(gè)屬于打包的JAR文件,包括外部依賴每個(gè)打包的JAR。正是這種元數(shù)據(jù),使Maven下載依賴你的遞歸地依賴,直到整棵樹的依賴關(guān)系是下載并放入您的本地存儲(chǔ)庫(kù)中。
  Maven存儲(chǔ)庫(kù)會(huì)詳細(xì)介紹Maven存儲(chǔ)庫(kù)簡(jiǎn)介,但這里是一個(gè)快速概述。
Maven有三種類型的存儲(chǔ)庫(kù):
本地存儲(chǔ)庫(kù)
中央存儲(chǔ)庫(kù)
遠(yuǎn)程存儲(chǔ)庫(kù)
  Maven搜索這些存儲(chǔ)庫(kù)的依賴性在上面的序列。首先在本地存儲(chǔ)庫(kù),然后在中央存儲(chǔ)庫(kù),和第三如果POM中指定遠(yuǎn)程存儲(chǔ)庫(kù)。

 

Here is a diagram illustrating the three repository types and their location:

這是一個(gè)圖說(shuō)明三個(gè)庫(kù)類型和位置:

 

   Maven Repository Types and Location.  Maven存儲(chǔ)庫(kù)類型和位置。

 

Local Repository
    A local repository is a directory on the developer's computer. This repository will contain all the dependencies Maven downloads. The same Maven repository is typically used for several different projects. Thus Maven only needs to download the dependencies once, even if multiple projects depends on them (e.g. Junit).
   Your own projects can also be built and installed in your local repository, using the mvn install command. That way your other projects can use the packaged JAR files of your own projects as external dependencies by specifying them as external dependencies inside their Maven POM files.
By default Maven puts your local repository inside your user home directory on your local computer. However, you can change the location of the local repository by setting the directory inside your Maven settings file. Your Maven settings file is also located in your user-home/.m2 directory and is calledsettings.xml. Here is how you specify another location for your local repository:


本地存儲(chǔ)庫(kù)
   本地存儲(chǔ)庫(kù)是一個(gè)開(kāi)發(fā)人員的計(jì)算機(jī)上的目錄。這個(gè)存儲(chǔ)庫(kù)將包含所有下載Maven的依賴關(guān)系。相同的Maven存儲(chǔ)庫(kù)通常用于不同的項(xiàng)目。因此Maven只需要下載的依賴關(guān)系,即使多個(gè)項(xiàng)目(例如Junit)取決于他們。
    自己的項(xiàng)目也可以建造和安裝在你的本地存儲(chǔ)庫(kù),使用mvn install命令。這樣你的其他項(xiàng)目可以使用JAR文件打包自己的項(xiàng)目外部依賴通過(guò)指定外部依賴關(guān)系在他們的Maven POM文件。
默認(rèn)Maven將您的本地存儲(chǔ)庫(kù)在本地電腦上用戶的主目錄。但是,你可以改變本地存儲(chǔ)庫(kù)的位置通過(guò)設(shè)置目錄在您的Maven設(shè)置文件。Maven設(shè)置文件也位于你的戶主/m2目錄和called settings.xml。這是你如何為你的本地存儲(chǔ)庫(kù):指定另一個(gè)位置.

<settings>
    <localRepository>
        d:\data\java\products\maven\repository
    </localRepository>
</settings>

 

Central Repository
    The central Maven repository is a repository provided by the Maven community. By default Maven looks in this central repository for any dependencies needed but not found in your local repository. Maven then downloads these dependencies into your local repository. You need no special configuration to access the central repository.
Remote Repository
   A remote repository is a repository on a web server from which Maven can download dependencies, just like the central repository. A remote repository can be located anywhere on the internet, or inside a local network.
   A remote repository is often used for hosting projects internal to your organization, which are shared by multiple projects. For instance, a common security project might be used across multiple internal projects. This security project should not be accessible to the outside world, and should thus not be hosted in the public, central Maven repository. Instead it can be hosted in an internal remote repository.

 

中央存儲(chǔ)庫(kù)
   中央Maven存儲(chǔ)庫(kù)是一個(gè)Maven存儲(chǔ)庫(kù)提供的社區(qū)。默認(rèn)Maven中央存儲(chǔ)庫(kù)中查找所需依賴關(guān)系,但沒(méi)有發(fā)現(xiàn)在你的本地存儲(chǔ)庫(kù)。Maven然后下載這些依賴關(guān)系到你的本地存儲(chǔ)庫(kù)。你不需要任何特殊配置訪問(wèn)中央存儲(chǔ)庫(kù)。
遠(yuǎn)程存儲(chǔ)庫(kù)
   一個(gè)遠(yuǎn)程存儲(chǔ)庫(kù)是一個(gè)Maven存儲(chǔ)庫(kù)web服務(wù)器上可以下載依賴,就像中央存儲(chǔ)庫(kù)。一個(gè)遠(yuǎn)程存儲(chǔ)庫(kù)可以位于任何地方在互聯(lián)網(wǎng)上,或者在一個(gè)本地網(wǎng)絡(luò)。
   一個(gè)遠(yuǎn)程存儲(chǔ)庫(kù)通常用于舉辦項(xiàng)目組織的內(nèi)部,是由多個(gè)項(xiàng)目共享。例如,一個(gè)共同的安全項(xiàng)目可能使用多個(gè)內(nèi)部項(xiàng)目。這個(gè)安全項(xiàng)目不應(yīng)該訪問(wèn)的外部世界,并因此不應(yīng)該駐留在公眾,中央Maven存儲(chǔ)庫(kù)。相反,它可以駐留在一個(gè)內(nèi)部的遠(yuǎn)程存儲(chǔ)庫(kù)。

 

   Dependencies found in a remote repository are also downloaded and put into your local repository by Maven.
   You can configure a remote repository in the POM file. Put the following XML elements right after the<dependencies> element:

您可以配置一個(gè)遠(yuǎn)程存儲(chǔ)庫(kù)的POM文件。把下面的XML元素之后<dependencies> element:

<repositories>
   <repository>
       <id>jenkov.code</id>
       <url>http://maven./maven2/lib</url>
   </repository>
</repositories>

 

Maven Build Life Cycles, Phases and Goals
  When Maven builds a software project it follows a build life cycle. The build life cycle is divided into build phases, and the build phases are divided into build goals. Maven build life cycles, build phases and goals are described in more detail in the Maven Introduction to Build Phases, but here I will give you a quick overview.
Build Life Cycles
Maven has 3 built-in build life cycles. These are:
       default
       clean
       site
    Each of these build life cycles takes care of a different aspect of building a software project. Thus, each of these build life cycles are executed independently of each other. You can get Maven to execute more than one build life cycle, but they will be executed in sequence, separately from each other, as if you had executed two separate Maven commands.
   The default life cycle handles everything related to compiling and packaging your project. The clean life cycle handles everything related to removing temporary files from the output directory, including generated source files, compiled classes, previous JAR files etc. The site life cycle handles everything related to generating documentation for your project. In fact, site can generate a complete website with documentation for your project.


Maven構(gòu)建生命周期、階段和目標(biāo)
    Maven構(gòu)建軟件項(xiàng)目的時(shí)候是一個(gè)構(gòu)建生命周期。構(gòu)建生命周期分為構(gòu)建階段,和構(gòu)建階段分為構(gòu)建目標(biāo)。Maven構(gòu)建生命周期、構(gòu)建階段和目標(biāo)更詳細(xì)地描述了Maven介紹構(gòu)建階段,但在這里我將給你一個(gè)快速概述。
建立生命周期
Maven 3內(nèi)置構(gòu)建生命周期。這些都是:
       默認(rèn)的
       清潔
       網(wǎng)站
    每一個(gè)構(gòu)建生命周期負(fù)責(zé)建立一個(gè)軟件項(xiàng)目的不同方面。因此,每一個(gè)構(gòu)建生命周期是彼此獨(dú)立地執(zhí)行。你可以得到Maven執(zhí)行多個(gè)構(gòu)建生命周期,但他們將按順序執(zhí)行,彼此分開(kāi),因?yàn)槿绻阌袃蓚€(gè)單獨(dú)的Maven命令執(zhí)行。
    缺省生命周期處理一切有關(guān)編譯和打包您的項(xiàng)目。清潔處理一切有關(guān)生命周期從輸出目錄刪除臨時(shí)文件,包括生成的源文件,編譯類,先前的JAR文件等。該網(wǎng)站生命周期處理一切相關(guān)的為您的項(xiàng)目生成文檔。事實(shí)上,網(wǎng)站可以生成一個(gè)完整的網(wǎng)站為您的項(xiàng)目文檔。

 

Build Phases
   Each build life cycle is divided into a sequence of build phases, and the build phases are again subdivided into goals. Thus, the total build process is a sequence of build life cycle(s), build phases and goals.
   You can execute either a whole build life cycle like clean or site, a build phase like install which is part of the default build life cycle, or a build goal like dependency:copy-dependencies. Note: You cannot execute the default life cycle directly. You have to specify a build phase or goal inside the default life cycle.
   When you execute a build phase, all build phases before that build phase in this standard phase sequence are executed. Thus, executing the install build phase really means executing all build phases before the install phase, and then execute the install phase after that.
   The default life cycle is of most interest since that is what builds the code. Since you cannot execute the default life cycle directly, you need to execute a build phase or goal from the default life cycle. The default life cycle has an extensive sequence of build phases and goals, ,so I will not describe them all here. The most commonly used build phases are:

 

構(gòu)建階段
    每個(gè)構(gòu)建生命周期分為一系列的構(gòu)建階段,和構(gòu)建階段又分為目標(biāo)。因此,整個(gè)構(gòu)建過(guò)程是構(gòu)建生命周期的序列,構(gòu)建階段和目標(biāo)。
   您可以執(zhí)行一個(gè)整體構(gòu)建生命周期清潔或網(wǎng)站,一個(gè)構(gòu)建階段像安裝默認(rèn)構(gòu)建生命周期的一部分,或構(gòu)建目標(biāo)像依賴:copy-dependencies。注意:你不能直接執(zhí)行thedefault生命周期。您必須指定一個(gè)構(gòu)建階段或目標(biāo)內(nèi)部默認(rèn)的生命周期。
    當(dāng)您執(zhí)行一個(gè)構(gòu)建階段,構(gòu)建階段之前,在執(zhí)行本標(biāo)準(zhǔn)相序建立階段。因此,執(zhí)行安裝構(gòu)建階段的真正含義之前執(zhí)行所有構(gòu)建階段安裝階段,然后執(zhí)行安裝階段。
缺省生命周期是最感興趣的,因?yàn)檫@就是構(gòu)建代碼。既然你不能直接執(zhí)行the default生命周期中,您需要執(zhí)行 一個(gè)構(gòu)建階段或目標(biāo)從默認(rèn)的生命周期。defaultlife周期有一個(gè)廣泛的序列構(gòu)建階段和目標(biāo),,所以我不會(huì)描述他們都在這里。最常用的構(gòu)建階段是:

Build Phase

Description

validate

Validates that the project is correct and all necessary information is available. This also makes sure the dependencies are downloaded.

compile

Compiles the source code of the project.

test

Runs the tests against the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.

package

Packs the compiled code in its distributable format, such as a JAR.

install

Install the package into the local repository, for use as a dependency in other projects locally.

deploy

Copies the final package to the remote repository for sharing with other developers and projects.

 

You execute one of these build phases by passing its name to the mvn command. Here is an example:

你執(zhí)行一個(gè)構(gòu)建階段通過(guò)mvn命令的名稱。這是一個(gè)例子:

mvn package

 

    This example executes the package build phase, and thus also all build phases before it in Maven's predefined build phase sequence.
If the standard Maven build phases and goals are not enough to build your project, you can create Maven plugins to add the extra build functionality you need.
Build Goals
   Build goals are the finest steps in the Maven build process. A goal can be bound to one or more build phases, or to none at all. If a goal is not bound to any build phase, you can only execute it by passing the goals name to the mvn command. If a goal is bound to multiple build phases, that goal will get executed during each of the build phases it is bound to.

 

這個(gè)例子執(zhí)行包構(gòu)建階段,因此也在Maven構(gòu)建階段之前的預(yù)定義的序列構(gòu)建階段。
   如果標(biāo)準(zhǔn)Maven構(gòu)建階段和目標(biāo)并不足以構(gòu)建您的項(xiàng)目,您可以創(chuàng)建Maven插件添加額外的構(gòu)建功能需要。
建立目標(biāo)
   建立目標(biāo)是最好的Maven構(gòu)建過(guò)程中的步驟。一個(gè)目標(biāo)可以綁定到一個(gè)或多個(gè)構(gòu)建階段,或根本沒(méi)有。如果一個(gè)目標(biāo)是沒(méi)有綁定到構(gòu)建階段,你只能通過(guò)執(zhí)行它的目標(biāo)名稱mvn命令。如果目標(biāo)是綁定到多個(gè)構(gòu)建階段,這一目標(biāo)將在每次執(zhí)行構(gòu)建階段的必然。

 

Maven Build Profiles
    Maven build profiles enable you to build your project using different configurations. Instead of creating two separate POM files, you can just specify a profile with the different build configuration, and build your project with this build profile when needed.
   You can read the full story about build profiles in the Maven POM reference under Profiles. Here I will give you a quick overview though.

 

Maven構(gòu)建配置文件
   Maven構(gòu)建配置文件使您能夠使用不同的配置構(gòu)建您的項(xiàng)目。而不是創(chuàng)建兩個(gè)單獨(dú)的POM文件,你可以指定一個(gè)配置文件與不同的構(gòu)建配置,并建立項(xiàng)目的構(gòu)建配置文件。
您可以閱讀完整的故事構(gòu)建配置文件下的Maven POM參考資料。在這里我將給你一個(gè)快速概述。

 

   Maven build profiles are specified inside the POM file, inside the profiles element. Each build profile is nested inside a profile element. Here is an example:

   Maven構(gòu)建配置文件指定在POM文件,內(nèi)部配置文件元素。每個(gè)構(gòu)建文件元素嵌套在一個(gè)概要文件。這是一個(gè)例子:

<project xmlns="http://maven./POM/4.0.0"
         xmlns:xsi="http://www./2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven./POM/4.0.0
   http://maven./xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>com.jenkov.crawler</groupId>
  <artifactId>java-web-crawler</artifactId>
  <version>1.0.0</version>
 
  <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>
 
</project>

 

   A build profile describes what changes should be made to the POM file when executing under that build profile. This could be changing the applications configuration file to use etc. The elements inside theprofile element will override the values of the elements with the same name further up in the POM.
   Inside the profile element you can see a activation element. This element describes the condition that triggers this build profile to be used. One way to choose what profile is being executed is in the settings.xml file. There you can set the active profile. Another way is to add -P profile-name to the Maven command line. See the profile documentation for more information.

 

   構(gòu)建配置文件描述了變化時(shí)應(yīng)該對(duì)POM文件執(zhí)行構(gòu)建配置文件。這可能是改變應(yīng)用程序配置文件使用等。theprofile元素內(nèi)的元素將會(huì)覆蓋具有相同名稱的元素的值進(jìn)一步砰的一聲。
   在配置文件元素可以看到激活元素。這個(gè)元素描述了使用條件,觸發(fā)這個(gè)構(gòu)建配置文件。選擇概要文件被執(zhí)行的一個(gè)方法是在settings.xml文件中。你可以設(shè)置當(dāng)前文件。另一種方法是- p配置文件名添加到Maven命令行??吹竭@個(gè)概要文件文檔的更多信息。

 

Maven Plugins
   Maven plugins enable you to add your own actions to the build process. You do so by creating a simple Java class that extends a special Maven class, and then create a POM for the project. The plugin should be located in its own project.
   To keep this tutorial short, I will refer to the Maven Plugin Developers Centre for more information about developing plugins.

 

Maven插件
   Maven插件使您可以添加自己的行動(dòng)來(lái)構(gòu)建過(guò)程。你這樣做,通過(guò)創(chuàng)建一個(gè)簡(jiǎn)單的Java,它擴(kuò)展了一個(gè)特殊的Maven,然后創(chuàng)建一個(gè)POM的項(xiàng)目。這個(gè)插件應(yīng)該位于自己的項(xiàng)目。
保持本教程,我將參考Maven插件開(kāi)發(fā)者中心開(kāi)發(fā)插件的更多信息。

 


目標(biāo)、用途、意圖

教程

因此

重點(diǎn)

概念

查找

聲稱

哲學(xué)

自動(dòng)構(gòu)建

通常

優(yōu)點(diǎn)

過(guò)程

使減少到最小

明確

繼承

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多