记录一个问题处理
通常发生在程序尝试加载或验证JAR文件时,其数字签名与文件内容不匹配。这多见于打包(如创建包含依赖的Fat JAR)或运行环境存在问题。
异常信息
ava.lang.SecurityException: Invalid signature file digest for Manifest main attributes
at sun.security.util.SignatureFileVerifier.processImpl (SignatureFileVerifier.java:330)
at sun.security.util.SignatureFileVerifier.process (SignatureFileVerifier.java:263)
at java.util.jar.JarVerifier.processEntry (JarVerifier.java:318)
报错路径:
报错原因:
Fat JAR打包:使用Maven Shade Plugin等工具创建包含所有依赖的"Fat JAR"时,如果多个依赖JAR都带有签名文件,这些文件可能会被错误地合并或包含进最终的JAR,导致签名冲突和验证失败
解决方案:
如果你的项目使用Maven构建,在pom.xml文件中配置maven-shade-plugin是根除此问题的最佳方法。在插件的配置中,排除所有依赖中的签名相关文件:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-shade-pluginartifactId>
<version>3.1.0version>
<executions>
<execution>
<phase>packagephase>
<goals>
<goal>shadegoal>
goals>
<configuration>
<filters>
<filter>
<artifact>*:*artifact>
<excludes>
<exclude>META-INF/*.SFexclude>
<exclude>META-INF/*.DSAexclude>
<exclude>META-INF/*.RSAexclude>
excludes>
filter>
filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>你的主类的完整路径mainClass>
transformer>
transformers>
configuration>
execution>
executions>
plugin>
plugins>
build>