Maven 阴影 jar 抛出异常

发布于 2024-12-18 14:02:01 字数 3030 浏览 3 评论 0原文

我有以下异常:

线程“main”中出现异常 java.lang.SecurityException:无清单 签名文件条目部分 javax/security/cert/CertificateException.class 在 sun.security.util.SignatureFileVerifier.verifySection(SignatureFileVerifier.java:380) 在 sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:231) 在 sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:176) 在 java.util.jar.JarVerifier.processEntry(JarVerifier.java:288) 在 java.util.jar.JarVerifier.update(JarVerifier.java:199) 在 java.util.jar.JarFile.initializeVerifier(JarFile.java:323) 在 java.util.jar.JarFile.getInputStream(JarFile.java:388) 在 sun.misc.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:692) 在 sun.misc.Resource.cachedInputStream(Resource.java:61) 在 sun.misc.Resource.getByteBuffer(Resource.java:144) 在 java.net.URLClassLoader.defineClass(URLClassLoader.java:256) 在 java.net.URLClassLoader.access$000(URLClassLoader.java:58) 在 java.net.URLClassLoader$1.run(URLClassLoader.java:197) 在 java.security.AccessController.doPrivileged(本机方法) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:190) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:306) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:247) 找不到主类:com.mainClass。程序将退出。

我的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>

I have the following Exception:

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.

My 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月蹉跎了容颜 2024-12-25 14:02:01

出现 SecurityException 是因为您的依赖项之一是签名的 jar。
当阴影插件重新打包这个 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

The SecurityException comes up because one of your dependencies is a signed jar.
As the shade plugin is repacking this jar, it gets invalid. -> SecurityException at launch

To solve the problem, you have to unsign the dependency jars while repacking them.
This can be done by simply not repacking the files that make the jar signed, using a filter:

<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>

This solution was extracted from here:
https://issues.apache.org/jira/browse/MSHADE-61

叹倦 2024-12-25 14:02:01

问题是因为java版本。
我没有注意到我的新ide自动使用ibm的java,当我将jre更改为sun的java时,它运行得很好:)

The problem is because of java version.
I didn't notice that my new ide automatically use ibm's java, when I change the jre to sun's java ,it works well:)

全部不再 2024-12-25 14:02:01

上面堆栈跟踪的最后一行说

找不到主类:com.mainClass。

也许类名中存在拼写错误,或者在调用插件之前未编译该类?

The last line of the stacktrace above says

Could not find the main class: com.mainClass.

Perhaps a typo in the classname or the class is not compiled before the plugin in invoked?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文