Invalid signature file digest for Manifest main attributes

Posted 悟初境

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Invalid signature file digest for Manifest main attributes相关的知识,希望对你有一定的参考价值。

正常使用打包插件如文档.

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>com.jimo.Main</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

Invalid signature file digest for Manifest main attributes

但有时我们在打完jar包运行会报错:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
        at sun.security.util.SignatureFileVerifier.processImpl(Unknown Source)
        at sun.security.util.SignatureFileVerifier.process(Unknown Source)
        at java.util.jar.JarVerifier.processEntry(Unknown Source)
        at java.util.jar.JarVerifier.update(Unknown Source)
        at java.util.jar.JarFile.initializeVerifier(Unknown Source)
        at java.util.jar.JarFile.ensureInitialization(Unknown Source)
        at java.util.jar.JavaUtilJarAccessImpl.ensureInitialization(Unknown Source)
        at sun.misc.URLClassPath$JarLoader$2.getManifest(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

这是由于混在一起后,很多其他文件在 META-INF下导致的,比如下面的 ECLIPSE.RSA, ECLIPSE.SF.

解决办法很简单,要么手动删除,要么通过插件配置过滤:

    <configuration>
        <transformers>
            <transformer
                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <mainClass>org.urbcomp.start.db.test.MiniHBaseCluster</mainClass>
            </transformer>
        </transformers>
        <filters>
            <filter>
                <artifact>*:*</artifact>
                <excludes>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                </excludes>
            </filter>
        </filters>
    </configuration>

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

Invalid signature file digest for Manifest main attributes

Invalid signature file digest for Manifest main attributes

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

eclipse中出现invalid LOC header (bad signature) cannot be read or is not a valid ZIP file

创建的jar包无法运行,出现java.lang.SecurityException: Invalid signature file digest for Manifest main attribute

创建的jar包无法运行,出现java.lang.SecurityException: Invalid signature file digest for Manifest main attribute