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 POMMaven
- Maven快速入門(四)Maven中的pom.xml檔案詳解MavenXML
- Maven的pom.xml檔案詳解MavenXML
- SpringBoot專案maven pom.xml警告Overriding managed version問題解決Spring BootMavenXML
- Python改寫maven的pom.xml檔案PythonMavenXML
- Maven - Non-resolvable parent POM: Failure to find xx:xx:pomMavenAI
- maven超級pom內容Maven
- Spring Boot 專案 Maven Install 出現的問題 [WARNING] The requested profile “pom.xml“ could not be activatedSpring BootMavenXML
- Eclipse中專案Maven相關配置EclipseMaven
- Maven專案中resources配置總結Maven
- pom-建立web專案錯誤Web
- eclipse中maven專案不顯示Maven Dependencies依賴EclipseMaven
- Maven根據pom檔案中的Profile標籤動態配置編譯選項Maven編譯
- maven專案構建報錯:Could not find artifact com.xxx.cloud:xxx-cloud:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POMMavenCloud
- 在spring boot專案(maven)中引入其他 spring boot專案Spring BootMaven
- Maven 專案文件Maven
- Maven 專案模板Maven
- Maven 教程之 pom.xml 詳解MavenXML
- 從Maven專案中獲取Jar包MavenJAR
- 在idea中利用spingboot建立maven專案IdeabootMaven
- Maven-POM中的各種scope的行為總結Maven
- IDEA專案已新增jar包,pom檔案,打包Maven卻一直報錯的幾種解決方法IdeaJARMaven
- Maven教程(Eclipse配置及maven專案)MavenEclipse
- [maven][spring boot] mvn spring-boot:run啟動時,指定pom檔案MavenSpring Boot
- IDEA建立Maven專案中踩過的坑IdeaMaven
- maven 專案轉化成 gradle 專案實踐MavenGradle
- MyEclipse - 通過Maven建立WebApp專案時,生成的專案名中總是包含Maven Webapp的問題EclipseMavenWebAPP
- IDEA Maven無法新增依賴到專案中IdeaMaven
- eclipse中maven專案failonmissingwebxml錯誤的修復EclipseMavenAIWebXML
- 在 NetBeans 中打包 Maven 專案的兩種方式BeanMaven
- Mybatis、maven專案中整合log4j (17)MyBatisMaven
- 關於spring新建專案pom.xml報紅SpringXML
- Maven:Non-resolvable parent POM: Failure to find錯誤MavenAI
- Maven專案打jar包MavenJAR
- 建立Maven專案出錯Maven
- Maven 構建 Java 專案MavenJava
- Java Maven專案推送到 Maven 中央倉庫JavaMaven