解决java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
一、问题来源
当项目依赖其他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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步