Maven Pom 包介紹

pom.xml 文件主要描述了項目包的依賴和項目構建時的配置,在默認的 pom.xml 包中分爲四大塊。

第一部分爲項目的描述信息:

<groupId>com.neo</groupId>
<artifactId>hello</artifactId>
<version>2.0.5.RELEASE</version>
<packaging>jar</packaging>

<name>hello</name>
<description>Demo project for Spring Boot</description>
  • roupId,項目的包路徑;
  • artifactId,項目名稱;
  • version,項目版本號;
  • packaging,一般有兩個值:jar、war,表示使用 Maven 打包時構建成 Jar 包還是 War 包;
  • name,項目名稱;
  • description,項目描述。

第二部分項目的依賴配置信息

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.0.5.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
  </dependency>
</dependencies>
  • parent,標籤內配置 Spring Boot 父級版本 spring-boot-starter-parent,Maven 支持項目的父子結構,引入父級後會默認繼承父級的配置;

  • dependencies,標籤內配置項目所需要的依賴包,Spring Boot 體系內的依賴組件不需要填寫具體版本號,spring-boot-starter-parent 維護了體系內所有依賴包的版本信息

第三部分爲構建時需要的公共變量

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
</properties>

上面配置了項目構建時所使用的編碼,輸出所使用的編碼,最後指定了項目使用的 JDK 版本。

第四部分爲構建配置

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

使用 Maven 構建 Spring Boot 項目必須依賴於 spring-boot-maven-plugin 組件,spring-boot-maven-plugin 能夠以 Maven 的方式爲應用提供 Spring Boot 的支持,即爲 Spring Boot 應用提供了執行 Maven 操作的可能。spring-boot-maven-plugin 能夠將 Spring Boot 應用打包爲可執行的 jar 或 war 文件,然後以簡單的方式運行 Spring Boot 應用。

 

以上即爲 pom.xml 文件基礎內容,幾乎所有的 Spring Boot 項目都會用到以上配置信息

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章