gpt4 book ai didi

Maven 阴影 jar 抛出异常

转载 作者:行者123 更新时间:2023-12-04 00:11:56 25 4
gpt4 key购买 nike

我有以下异常:

Exception in thread "main" java.lang.SecurityException: no manifiest section for signature file entry javax/security/cert/CertificateException.class at sun.security.util.SignatureFileVerifier.verifySection(SignatureFileVerifier.java:380) at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:231) at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:176) at java.util.jar.JarVerifier.processEntry(JarVerifier.java:288) at java.util.jar.JarVerifier.update(JarVerifier.java:199) at java.util.jar.JarFile.initializeVerifier(JarFile.java:323) at java.util.jar.JarFile.getInputStream(JarFile.java:388) at sun.misc.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:692) at sun.misc.Resource.cachedInputStream(Resource.java:61) at sun.misc.Resource.getByteBuffer(Resource.java:144) at java.net.URLClassLoader.defineClass(URLClassLoader.java:256) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) Could not find the main class: com.mainClass. Program will exit.



我的pom:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filter>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.mainClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

最佳答案

SecurityException出现是因为您的依赖项之一是签名的 jar。
由于 shade 插件正在重新打包这个 jar,它变得无效。 -> SecurityException发布时

为了解决这个问题,你必须在重新打包它们时取消对依赖 jar 的签名。
这可以通过使用过滤器简单地不重新打包使 jar 签名的文件来完成:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>stand-alone</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>stand-alone</shadedClassifierName>
<filters>
<filter>
<!--
Exclude files that sign a jar
(one or multiple of the dependencies).
One may not repack a signed jar without
this, or you will get a
SecurityException at program start.
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/*.INF</exclude> <!-- This one may not be required -->
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>

这个解决方案是从这里提取的:
https://issues.apache.org/jira/browse/MSHADE-61

关于Maven 阴影 jar 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8302022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com