解決java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
阿新 • • 發佈:2020-06-28
一、問題來源
當專案依賴其他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