一、問題來源
當項目依賴其他jar包的時候,打出的jar包執行出錯,拋出標題中的異常。
原因:因為依賴jar包中的META-INF中有多余的.SF文件與當前jar包沖突。
二、解決方案
2.1 打包前排除
maven項目在pom.xml文件:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.1.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>[mvean項目啟動類的路徑,例如:com.alarm.mainclass]</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build>
2.2 打包后刪除
在打完的jar包執行 zip -d your.jar 'META-INF/.SF' 'META-INF/.RSA' 'META-INF/*SF'
參考鏈接:
1.https://www.jianshu.com/p/cd1f1b33a41a
2.https://blog.csdn.net/tian_shi_hei_de/article/details/78490392