国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

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

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

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

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

<!--配置項--><properties> <!--自定義配置--> <project.jar.output.directory>E:/IDEAFile/file-copy/target/project</project.jar.output.directory></properties><build> <plugins> <!--項目依賴的jar文件,放置默認配置目錄下--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- 設置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插件復制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復制到指定的目錄下--> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <!-- 在maven進行package的時候執行--> <phase>package</phase> <configuration> <tasks><!--todir:是將要復制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及配置文件進行壓縮打包到指定目錄:

<plugins> <!-- 項目依賴的jar文件,放置默認配置目錄下--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- 設置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> <!-- 項目文件處理 --> <fileSets> <!--配置文件輸出位置根目錄文件夾下--> <fileSet> <directory>${basedir}/src/main/resources</directory> <includes> <include>**</include> </includes> <filtered>true</filtered> <outputDirectory>${file.separator}</outputDirectory> </fileSet> <!-- 項目代碼生成的jar文件放在根目錄 --> <fileSet> <directory>${project.build.directory}</directory> <outputDirectory>${file.separator}</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets></assembly>

到此這篇關于Spring Boot使用Maven自定義打包方式的文章就介紹到這了,更多相關Spring Boot Maven自定義打包內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 亚洲一区二区三区不卡在线播放 | 91精品啪在线观看国产91九色 | 91资源在线播放 | 九九精品视频在线播放 | 高清免费国产在线观看 | 中文国产成人精品久久一区 | 免费人成黄页在线观看视频国产 | 色久网 | 久久午夜鲁丝片午夜精品 | 欧美熟videos肥婆 | 亚洲欧美日韩另类精品一区二区三区 | 一级毛片私人影院免费 | 国产亚洲精品自在线观看 | 欧美一级特黄aaaaaa在线看片 | 久草在线观看资源 | 亚洲品质自拍视频网站 | 免费在线精品视频 | 99久久九九| 欧美aaaaaaaaa| 国产伦精品一区二区三区无广告 | 久草免费在线播放视频 | 亚洲小视频在线观看 | 国产一级视频播放 | 欧美日韩国产高清一区二区三区 | 中文字幕在线看视频一区二区三区 | 怡红院免费va男人的天堂 | 九九99| 一级片免 | 一级欧美一级日韩毛片99 | 国产毛片一级国语版 | 中文字幕在线观看网址 | 九色91 | 欧美视频亚洲视频 | 精品免费国产一区二区三区 | 一本久道久久综合中文字幕 | 一本到不卡 | 国产高清av在线播放 | 成人国产亚洲欧美成人综合网 | a毛片在线看片免费 | 国产精品免费大片一区二区 | 日韩城人视频 |