解决java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

Posted 明明不平凡

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决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

以上是关于解决java.lang.SecurityException: Invalid signature file digest for Manifest main attributes的主要内容,如果未能解决你的问题,请参考以下文章

云原生景观:可观察性和分析解决了什么问题?如何解决的?

vs2008解决方案资源管理器不显示解决方案

什么是 沙盒解决方案

解决PowerShell乱码问题

如何解决解决方案中现有项目的c#CS0006错误

关于问题解决与事件解决的思考