日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Maven build标签

發布時間:2023/11/27 生活经验 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Maven build标签 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言:

? ?<build >設置,主要用于編譯設置

1.分類

在Maven的pom.xml文件中,存在如下兩種<build>:

(1)全局配置(project build)

? ? ? ? ?針對整個項目的所有情況都有效

(2)配置(profile build)

? ? ? ? ? ?針對不同的profile配置

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">  ...  <!-- "Project Build" contains elements of the BaseBuild set and the Build set-->  <build>...</build>  <profiles>  <profile>  <!-- "Profile Build" contains elements of the BaseBuild set only -->  <build>...</build>  </profile>  </profiles>  
</project>  

說明:

一種<build>被稱為Project Build,即是<project>的直接子元素。

另一種<build>被稱為Profile Build,即是<profile>的直接子元素。

Profile Build包含了基本的build元素,而Project Build還包含兩個特殊的元素,即各種<...Directory>和<extensions>。

2. 配置說明

1.基本元素

示例如下

<build>  <defaultGoal>install</defaultGoal>  <directory>${basedir}/target</directory>  <finalName>${artifactId}-${version}</finalName> 
<filters>
<filter>filters/filter1.properties</filter>
</filters>?
...
</build>

? ? ? ? ? ? 1)defaultGoal

? ? ? ? ? ? ? ? ? ? 執行build任務時,如果沒有指定目標,將使用的默認值。

? ? ? ? ? ? ? ? ? ? 如上配置:在命令行中執行mvn,則相當于執行mvn install

? ? ? ? ? ? ? 2)directory
? ? ? ? ? ? ? ? ? ? ?build目標文件的存放目錄,默認在${basedir}/target目錄

? ? ? ? ? ? ? 3)finalName

? ? ? ? ? ? ? ? ? ? ?build目標文件的名稱,默認情況為${artifactId}-${version}

? ? ? ? ? ? ? 4)filter

? ? ? ? ? ? ? ? ? ? ?定義*.properties文件,包含一個properties列表,該列表會應用到支持filter的resources中。

? ? ? ? ? ? ? ? ? ? ?也就是說,定義在filter的文件中的name=value鍵值對,會在build時代替${name}值應用到resources中。

? ? ? ? ? ? ? ? ? ? ?maven的默認filter文件夾為${basedir}/src/main/filters

?2. Resources配置

? ? ? ? ? ? ? ? ?用于包含或者排除某些資源文件

? ??

<build>  ...  <resources>  <resource>  <targetPath>META-INF/plexus</targetPath>  <filtering>true</filtering>  <directory>${basedir}/src/main/plexus</directory>  <includes>  <include>configuration.xml</include>  </includes>  <excludes>  <exclude>**/*.properties</exclude>  </excludes>  </resource>  </resources>  <testResources>  ...  </testResources>  ...  
</build>  

? ? ? ? ? ? ?

? ? ? ? ? ? ? 1)resources

? ? ? ? ? ? ? ? ? ? 一個resources元素的列表。每一個都描述與項目關聯的文件是什么和在哪里

? ? ? ? ? ? ? 2)targetPath

? ? ? ? ? ? ? ? ? ? 指定build后的resource存放的文件夾,默認是basedir。

? ? ? ? ? ? ? ? ? ? 通常被打包在jar中的resources的目標路徑是META-INF

? ? ? ? ? ? ?3)filtering

? ? ? ? ? ? ? ? ? ? true/false,表示為這個resource,filter是否激活
? ? ? ? ? ? ?4)directory

? ? ? ? ? ? ? ? ? ? 定義resource文件所在的文件夾,默認為${basedir}/src/main/resources

? ? ? ? ? ? ?5)includes

? ? ? ? ? ? ? ? ? ? 指定哪些文件將被匹配,以*作為通配符

? ? ? ? ? ? ?6)excludes

? ? ? ? ? ? ? ? ? ?指定哪些文件將被忽略

? ? ? ? ? ? ?7)testResources

? ? ? ? ? ? ? ? ? ?定義和resource類似,只不過在test時使用

?3 plugins配置

? ? ? ? ? ? ? ? ? 用于指定使用的插件

? ? ? ?

<build>  ...  <plugins>  <plugin>  <groupId>org.apache.maven.plugins</groupId>  <artifactId>maven-jar-plugin</artifactId>  <version>2.0</version>  <extensions>false</extensions>  <inherited>true</inherited>  <configuration>  <classifier>test</classifier>  </configuration>  <dependencies>...</dependencies>  <executions>...</executions>  </plugin>  </plugins>  
</build>  

? 4? pluginManagement配置

? ? ? ? ? pluginManagement的配置和plugins的配置是一樣的,只是用于繼承,使得可以在孩子pom中使用。

? ? ? ?父pom:

<build>  ...  <pluginManagement>  <plugins>  <plugin>  <groupId>org.apache.maven.plugins</groupId>  <artifactId>maven-jar-plugin</artifactId>  <version>2.2</version>  <executions>  <execution>  <id>pre-process-classes</id>  <phase>compile</phase>  <goals>  <goal>jar</goal>  </goals>  <configuration>  <classifier>pre-process</classifier>  </configuration>  </execution>  </executions>  </plugin>  </plugins>  </pluginManagement>  ...  
</build>  

? 則在子pom中,我們只需要配置:

<build>  ...  <plugins>  <plugin>  <groupId>org.apache.maven.plugins</groupId>  <artifactId>maven-jar-plugin</artifactId>  </plugin>  </plugins>  ...  
</build>  

?這樣大大簡化了孩子pom的配置

轉載于:https://www.cnblogs.com/whx7762/p/7911890.html

總結

以上是生活随笔為你收集整理的Maven build标签的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。