久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

詳解Spring Boot使用Maven自定義打包方式

瀏覽:21日期:2023-07-27 15:50:26

前言:本文將告訴你如何將程序Jar與與依賴Jar及配置文件分離打包,以下列舉了兩種不同Maven打包方式,其打包效果一致!

一、第一種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>

到此這篇關(guān)于Spring Boot使用Maven自定義打包方式的文章就介紹到這了,更多相關(guān)Spring Boot Maven自定義打包內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 色婷婷在线视频观看 | 欧美日韩国产综合视频 | 97男人的天堂 | www.久久99 | 91激情视频 | 久久久久免费观看 | 久久激情网站 | 日韩视频在线观看 | 国产精品高清在线 | 黄色片在线免费观看 | 中文字幕一区二区三区在线视频 | 仙踪林久久久久久久999 | 久久成人av| 久久com | 成人亚洲一区二区 | a级性视频| 久久久99国产精品免费 | 国产精品久久久久久久久 | 午夜精品福利网 | 精品久久久久久久久久久久 | 日本人做爰大片免费观看一老师 | 91久久精品一区二区别 | 成年人性视频 | 国产精品久久久久久久久软件 | 欧美一二三区在线 | 黄色三级网站 | 日韩中文字幕在线播放 | 欧美a在线 | 精品一区免费 | 免费在线成人 | 日b片| 久久婷婷国产麻豆91天堂 | 高清xxxx | 日韩精品1区 | 国产精品一区二区三区免费 | 欧洲亚洲一区 | 国产黄色一级大片 | 久久九九视频 | 九九亚洲精品 | 精品人人 | 精品一区二区不卡 |