Springboot jar主清單屬性丟失解決方案
在開(kāi)發(fā)中,用到springboot項(xiàng)目,當(dāng)打包后部署運(yùn)行時(shí),出現(xiàn)了這個(gè)問(wèn)題,網(wǎng)上搜了好多,又是加META-INF配置,又是加啥的,感覺(jué)springboot這么方便,這種問(wèn)題怎么可能會(huì)搞這么復(fù)雜,于是研究了一下:
首先我們項(xiàng)目要依賴springboot的parent或者引入spring-boot-dependencies
或者
這樣就將springboot的pom文件導(dǎo)入了我們的項(xiàng)目,然后還要再要運(yùn)行的jar包中寫(xiě)入插件:
當(dāng)使用繼承spring-boot-starter-parent時(shí),就會(huì)出現(xiàn)標(biāo)志,表示是繼承自父類的,然后我們點(diǎ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>
注意到里面有一個(gè)${start-class}變量,這個(gè)變量在parent的pom文件中并沒(méi)有定義,那么我們就在自己要打jar包運(yùn)行的模塊定義這個(gè)變量:
然后再打包,就可以直接通過(guò)java -jar *.jar 運(yùn)行項(xiàng)目了
如果不是繼承自parnetxml,而是選擇第一種,導(dǎo)入dependencies的方式:
那么就要改一下前面的spring-boot-maven-plugin插件,
我們需要指定打包路徑的main方法,這樣就可以直接打包通過(guò) java -jar *.jar的方式運(yùn)行了
重要的是一定要定義start-class變量
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 以PHP代碼為實(shí)例詳解RabbitMQ消息隊(duì)列中間件的6種模式2. html小技巧之td,div標(biāo)簽里內(nèi)容不換行3. PHP字符串前后字符或空格刪除方法介紹4. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法5. nestjs實(shí)現(xiàn)圖形校驗(yàn)和單點(diǎn)登錄的示例代碼6. AspNetCore&MassTransit Courier實(shí)現(xiàn)分布式事務(wù)的詳細(xì)過(guò)程7. XML入門的常見(jiàn)問(wèn)題(一)8. jsp cookie+session實(shí)現(xiàn)簡(jiǎn)易自動(dòng)登錄9. css進(jìn)階學(xué)習(xí) 選擇符10. Echarts通過(guò)dataset數(shù)據(jù)集實(shí)現(xiàn)創(chuàng)建單軸散點(diǎn)圖
