当前位置: 首页 > 知识库问答 >
问题:

无效的签名文件摘要的清单主要属性w/Jetty和Maven阴影插件

高朝明
2023-03-14

我见过其他一些这样的人

  • "无效的签名文件"当试图运行一个. jar
  • 异常在线程"main"java.lang.Security异常:无效的签名文件摘要的清单主属性
  • JavaFX项目的有效JAR签名

我们将Jetty与Maven Shade插件一起用于开源应用程序:

https://github.com/OneBusAway/onebusaway-gtfs-realtime-from-nextbus-cli

我们在生成中开始出现以下错误:

$ java -jar onebusaway-gtfs-realtime-from-nextbus-cli.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.getInputStream(Unknown Source)
    at sun.misc.URLClassPath$JarLoader$2.getInputStream(Unknown Source)
    at sun.misc.Resource.cachedInputStream(Unknown Source)
    at sun.misc.Resource.getByteBuffer(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)

以下是我们的问题追踪器上的问题:

https://github.com/OneBusAway/onebusaway-gtfs-realtime-from-nextbus-cli/issues/6

共有1个答案

於鸿羲
2023-03-14

看起来这是Jetty中的一个bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=371954

从上述错误报告中:

javax有一个问题。servlet-2.5。0.v201103041518。jetty-7.6上的罐子包装。1.v20120215依赖:在javax的META-INF目录中。servlet jar是ECLIPSEF中找到的文件。RSA和ECLIPSEF。旧金山。

如果您使用使用jetty的maven生成了一个jar,那么您会在最后一个jar的META-INF目录中得到这两个文件,如果您运行它,您会得到一个异常

java。lang.SecurityException:清单主属性的签名文件摘要无效

修复方法是从生成的jar中排除2个有问题的文件。

通过将maven shade插件添加到POM,可以排除不需要的文件:

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-shade-plugin</artifactId>
 <version>1.4</version>
 <executions>
  <execution>
   <goals>
    <goal>shade</goal>
   </goals>
   <configuration>
     <filters>
    <filter>
          <artifact>org.eclipse.jetty.orbit:javax.servlet</artifact>
        <excludes>
          <exclude>META-INF/ECLIPSEF.RSA</exclude>
              <exclude>META-INF/ECLIPSEF.SF</exclude>
              <exclude>META-INF/eclipse.inf</exclude>
        </excludes>
        </filter>
       </filters>
    </configuration>
   </execution>
  </executions>
</plugin>

添加:

<filters>
    <filter>
        <artifact>org.eclipse.jetty.orbit:javax.servlet</artifact>
            <excludes>
                <exclude>META-INF/ECLIPSEF.RSA</exclude>
                <exclude>META-INF/ECLIPSEF.SF</exclude>
                <exclude>META-INF/eclipse.inf</exclude>
            </excludes>
    </filter>
</filters>

...pom.xml为我们工作。

 类似资料: