Maven中POM專案物件模型
- POM代表專案物件模型,它是Maven中工作的基本單位,這是一個XML檔案,它始終儲存在該專案基本目錄中的pom.xml檔案中。
- POM包含的專案是使用Maven來構建的,它用來包含各種配置資訊。
- POM也包含了目標和外掛。在執行任務和目標時,Maven會使用當前目錄中的POM.它讀取POM得到所需要的配置資訊,然後執行目標,部分的配置可以在POM下使用如下:
project dependencies、plugins、goals、build profiles、project version、developers、mailing list - 建立一個POM之前,應該先決定專案組(groupId),它的名字(artifacId)和版本,因為這些屬性在專案倉庫是唯一的標識。
- POM示例:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>testWeb</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
要注意的是,每個專案只有一個POM檔案。
- 所有的 POM 檔案要專案元素必須有三個必填欄位: groupId(專案組編號),artifactId(專案的ID),version(版本號)
- 在庫中的專案符號是:groupId:artifactId:version
- pom.xml 的根元素是 project,它有三個主要的子節點。
- 所有的POM繼承自父類(儘管明確界定)。這個基礎的 POM 被稱為超級 POM,幷包含繼承預設值。 Maven使用有效的POM(超級POM加專案配置的配置)執行有關目標。它可以幫助開發人員指定最低配置的詳細資訊寫在 pom.xml 中。雖然配置可以很容易被覆蓋。 一個簡單的方法來看看超級POM的預設配置,通過執行下面的命令:mvn help:effective-pom 建立一個 pom.xml。
<!-- -->
<!-- ====================================================================== -->
<!-- ====================================================================== -->
<!-- -->
<!-- Effective POM for project 'com.test:testWeb:jar:1.0-SNAPSHOT' -->
<!-- -->
<!-- ====================================================================== -->
<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.test</groupId>
<artifactId>testWeb</artifactId>
<version>1.0-SNAPSHOT</version>
<name>testWeb</name>
<url>http://www.example.com</url>
<properties>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>C:\software\develop\workplace\testWeb\src\main\java</source
Directory>
<scriptSourceDirectory>C:\software\develop\workplace\testWeb\src\main\script
s</scriptSourceDirectory>
<testSourceDirectory>C:\software\develop\workplace\testWeb\src\test\java</te
stSourceDirectory>
<outputDirectory>C:\software\develop\workplace\testWeb\target\classes</outpu
tDirectory>
<testOutputDirectory>C:\software\develop\workplace\testWeb\target\test-class
es</testOutputDirectory>
<resources>
<resource>
<directory>C:\software\develop\workplace\testWeb\src\main\resources</dir
ectory>
</resource>
</resources>
<testResources>
<testResource>
<directory>C:\software\develop\workplace\testWeb\src\test\resources</dir
ectory>
</testResource>
</testResources>
<directory>C:\software\develop\workplace\testWeb\target</directory>
<finalName>testWeb-1.0-SNAPSHOT</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>C:\software\develop\workplace\testWeb\target\site
</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>C:\software\develop\workplace\testWeb\target\site
</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>C:\software\develop\workplace\testWeb\target\site</ou
tputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<outputDirectory>C:\software\develop\workplace\testWeb\target\site</outputDi
rectory>
</reporting>
</project>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.947 s
[INFO] Finished at: 2018-09-12T16:34:29+08:00
[INFO] Final Memory: 12M/183M
[INFO] ------------------------------------------------------------------------
相關文章
- 關於maven的核心pom(專案物件模型)的一些理解Maven物件模型
- 建立Maven專案出錯 pom出錯Maven
- 新建maven專案pom報錯的問題Maven
- Maven專案中POM.xml檔案內的標籤大全詳解MavenXML
- maven專案打包時生成dependency-reduced-pom.xmlMavenXML
- maven新建Spring MVC + MyBatis + Oracle的Web專案中pom.xml檔案MavenSpringMVCMyBatisOracleWebXML
- Maven中pom.xml解析MavenXML
- Maven的pom檔案那些事Maven
- Maven快速入門(四)Maven中的pom.xml檔案詳解MavenXML
- 如何在maven專案的pom.xml檔案中新增jar包MavenXMLJAR
- Maven中的pom.xml詳解MavenXML
- Maven的pom.xml檔案詳解MavenXML
- Maven pom.xml檔案配置詳解MavenXML
- 使用maven搭建hibernate的pom檔案配置Maven
- maven的pom檔案的所有元素的用法。Maven
- Python改寫maven的pom.xml檔案PythonMavenXML
- Maven - Non-resolvable parent POM: Failure to find xx:xx:pomMavenAI
- maven 在pom檔案下配置預設的jdk版本MavenJDK
- Maven專案中resources配置總結Maven
- maven專案匯入myeclipse中MavenEclipse
- Eclipse中Maven專案pom.xml檔案沒有錯,但一直有紅叉的解決辦法EclipseMavenXML
- eclipse建maven pom報錯EclipseMaven
- SpringBoot專案maven pom.xml警告Overriding managed version問題解決Spring BootMavenXML
- pom-建立web專案錯誤Web
- Maven根據pom檔案中的Profile標籤動態配置編譯選項Maven編譯
- eclipse中maven專案不顯示Maven Dependencies依賴EclipseMaven
- 從Maven專案中獲取Jar包MavenJAR
- Eclipse中專案Maven相關配置EclipseMaven
- Maven-POM中的各種scope的行為總結Maven
- Maven 教程之 pom.xml 詳解MavenXML
- Maven 專案模板Maven
- Maven 專案文件Maven
- 查詢jar中的pom檔案JAR
- 在spring boot專案(maven)中引入其他 spring boot專案Spring BootMaven
- IntelliJ IDEA中建立Web聚合專案(Maven多模組專案)IntelliJIdeaWebMaven
- Maven之pom.xml與setting.xml配置檔案詳解MavenXML
- 建立Maven模板專案Maven
- maven 建立web專案MavenWeb