怎么在SpringBoot中使用Maven進(jìn)行打包-創(chuàng)新互聯(lián)

本篇文章給大家分享的是有關(guān)怎么在Spring Boot中使用Maven進(jìn)行打包,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

為企業(yè)提供成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、網(wǎng)站優(yōu)化、網(wǎng)絡(luò)營銷推廣、競(jìng)價(jià)托管、品牌運(yùn)營等營銷獲客服務(wù)。成都創(chuàng)新互聯(lián)公司擁有網(wǎng)絡(luò)營銷運(yùn)營團(tuán)隊(duì),以豐富的互聯(lián)網(wǎng)營銷經(jīng)驗(yàn)助力企業(yè)精準(zhǔn)獲客,真正落地解決中小企業(yè)營銷獲客難題,做到“讓獲客更簡單”。自創(chuàng)立至今,成功用技術(shù)實(shí)力解決了企業(yè)“網(wǎng)站建設(shè)、網(wǎng)絡(luò)品牌塑造、網(wǎng)絡(luò)營銷”三大難題,同時(shí)降低了營銷成本,提高了有效客戶轉(zhuǎn)化率,獲得了眾多企業(yè)客戶的高度認(rèn)可!

一、第一種Maven打包方式,將jar及resources下全部配置文件,拷貝到指定目錄:


<!--配置項(xiàng)--><properties> <!--自定義配置--> <project.jar.output.directory>E:/IDEAFile/file-copy/target/project</project.jar.output.directory></properties>
<build>
  <plugins>
   <!--項(xiàng)目依賴的jar文件,放置默認(rèn)配置目錄下-->
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>

   <!-- 設(shè)置jar的入口類 -->
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
    <configuration>
     <archive>
      <manifest>
       <addClasspath>true</addClasspath>
       <classpathPrefix>lib/</classpathPrefix>
       <mainClass>com.example.filecopy.FileCopyApplication</mainClass>
      </manifest>
     </archive>
    </configuration>
   </plugin>

  <!-- 使用maven-resources-plugin插件復(fù)制resources目錄下所有文件到指定的路徑-->
   <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
     <execution>
      <id>copy-resources</id>
      <phase>validate</phase>
      <goals>
       <goal>copy-resources</goal>
      </goals>
      <configuration>
       <outputDirectory>${project.build.directory}/project</outputDirectory>
       <resources>
        <resource>
         <directory>src/main/resources</directory>
         <filtering>true</filtering>
        </resource>
       </resources>
      </configuration>
     </execution>
    </executions>
   </plugin>

   <!--使用maven-antrun-plugin插件將jar復(fù)制到指定的目錄下-->
   <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
     <execution>
      <!-- 在maven進(jìn)行package的時(shí)候執(zhí)行-->
      <phase>package</phase>
      <configuration>
       <tasks>
        <!--todir:是將要復(fù)制jar包到的地方,overwrite:是否重寫-->
        <copy todir="${project.jar.output.directory}" overwrite="true">
         <!--獲取父目錄下的target文件夾中的jar-->
         <fileset dir="${project.build.directory}">
          <include name="*.jar"/>
         </fileset>
        </copy>
       </tasks>
      </configuration>
      <goals>
       <goal>run</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>

第二種Maven打包方式使用 assembly插件,將jar及配置文件進(jìn)行壓縮打包到指定目錄:

<plugins>
   <!-- 項(xiàng)目依賴的jar文件,放置默認(rèn)配置目錄下-->
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>

   <!-- 設(shè)置jar的入口類-->
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
    <configuration>
     <archive>
      <manifest>
       <addClasspath>true</addClasspath>
       <classpathPrefix>lib/</classpathPrefix>
       <mainClass>com.example.filecopy.FileCopyApplication</mainClass>
      </manifest>
     </archive>
    </configuration>
   </plugin>

    <!--assembly插件-->
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
     <!--指定壓縮包名稱-->
     <finalName>project</finalName>
     <!--指定assembly配置文件配置-->
     <descriptors>
      <descriptor>/assembly/assembly.xml</descriptor>
     </descriptors>
     <!--打包tar.gz輸出target文件夾中-->
     <outputDirectory>${project.build.directory}</outputDirectory>
     <appendAssemblyId>false</appendAssemblyId>
    </configuration>
    <executions>
     <execution>
      <phase>package</phase>
      <goals>
       <goal>single</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
  </plugins>

assembly文件:

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
 <id>leaves</id>
 <formats>
  <!--壓縮文件形式 可選 zip tar.gz等 -->
  <format>zip</format>
 </formats>
 <includeBaseDirectory>true</includeBaseDirectory>

 <!-- 項(xiàng)目文件處理 -->
 <fileSets>
  <!--配置文件輸出位置根目錄文件夾下-->
  <fileSet>
   <directory>${basedir}/src/main/resources</directory>
   <includes>
    <include>**</include>
   </includes>
   <filtered>true</filtered>
   <outputDirectory>${file.separator}</outputDirectory>
  </fileSet>

  <!-- 項(xiàng)目代碼生成的jar文件放在根目錄 -->
  <fileSet>
   <directory>${project.build.directory}</directory>
   <outputDirectory>${file.separator}</outputDirectory>
   <includes>
    <include>*.jar</include>
   </includes>
  </fileSet>
 </fileSets>
</assembly>

以上就是怎么在Spring Boot中使用Maven進(jìn)行打包,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

分享名稱:怎么在SpringBoot中使用Maven進(jìn)行打包-創(chuàng)新互聯(lián)
URL鏈接:http://muchs.cn/article44/djijhe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、商城網(wǎng)站、建站公司、做網(wǎng)站、App設(shè)計(jì)、網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)