久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

Springboot jar主清單屬性丟失解決方案

瀏覽:11日期:2023-05-12 17:54:01

在開發(fā)中,用到springboot項目,當打包后部署運行時,出現(xiàn)了這個問題,網(wǎng)上搜了好多,又是加META-INF配置,又是加啥的,感覺springboot這么方便,這種問題怎么可能會搞這么復(fù)雜,于是研究了一下:

首先我們項目要依賴springboot的parent或者引入spring-boot-dependencies

Springboot jar主清單屬性丟失解決方案

或者

Springboot jar主清單屬性丟失解決方案

這樣就將springboot的pom文件導(dǎo)入了我們的項目,然后還要再要運行的jar包中寫入插件:

Springboot jar主清單屬性丟失解決方案

當使用繼承spring-boot-starter-parent時,就會出現(xiàn)標志,表示是繼承自父類的,然后我們點到spring-boot-starter-parent的pom文件中,查看插件部分:

<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>repackage</id> <goals><goal>repackage</goal> </goals> </execution> </executions> <configuration> <mainClass>${start-class}</mainClass> </configuration> </plugin> <plugin> <artifactId>maven-shade-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals><goal>shade</goal> </goals> <configuration><transformers> <transformer implementation='org.apache.maven.plugins.shade.resource.AppendingTransformer'> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation='org.springframework.boot.maven.PropertiesMergingResourceTransformer'> <resource>META-INF/spring.factories</resource> </transformer> <transformer implementation='org.apache.maven.plugins.shade.resource.AppendingTransformer'> <resource>META-INF/spring.schemas</resource> </transformer> <transformer implementation='org.apache.maven.plugins.shade.resource.ServicesResourceTransformer'/> <transformer implementation='org.apache.maven.plugins.shade.resource.ManifestResourceTransformer'> <mainClass>${start-class}</mainClass> </transformer></transformers> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.1.12.RELEASE</version> </dependency> </dependencies> <configuration> <keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope> <createDependencyReducedPom>true</createDependencyReducedPom> <filters> <filter><artifact>*:*</artifact><excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude></excludes> </filter> </filters> </configuration> </plugin>

注意到里面有一個${start-class}變量,這個變量在parent的pom文件中并沒有定義,那么我們就在自己要打jar包運行的模塊定義這個變量:

Springboot jar主清單屬性丟失解決方案

然后再打包,就可以直接通過java -jar *.jar 運行項目了

如果不是繼承自parnetxml,而是選擇第一種,導(dǎo)入dependencies的方式:

Springboot jar主清單屬性丟失解決方案

那么就要改一下前面的spring-boot-maven-plugin插件,

Springboot jar主清單屬性丟失解決方案

我們需要指定打包路徑的main方法,這樣就可以直接打包通過 java -jar *.jar的方式運行了

重要的是一定要定義start-class變量

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 静海县| 西青区| 福安市| 铁力市| 鹤山市| 措勤县| 岱山县| 杨浦区| 辽宁省| 廊坊市| 新闻| 永川市| 义乌市| 介休市| 婺源县| 嘉义县| 砀山县| 仁怀市| 潞城市| 吉首市| 扎囊县| 海伦市| 普宁市| 梁河县| 西盟| 固阳县| 保康县| 汉寿县| 会昌县| 防城港市| 东阿县| 湘乡市| 菏泽市| 牡丹江市| 台东县| 沾化县| 嫩江县| 麻城市| 宁安市| 昭平县| 全椒县|