【问题标题】:Maven shade jar throw exceptionMaven shade jar 抛出异常
【发布时间】:2012-01-08 06:38:40
【问题描述】:

我有以下例外:

线程“主”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>

【问题讨论】:

    标签: maven exception maven-shade-plugin


    【解决方案1】:

    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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        上面stacktrace的最后一行说

        找不到主类:com.mainClass。

        可能是类名中的拼写错误或在调用插件之前未编译该类?

        【讨论】:

        • 抱歉,我认为这不是名称的问题。或者它应该给出异常为 noclassdeffoundexception。
        猜你喜欢
        • 2023-03-15
        • 2011-11-13
        • 1970-01-01
        • 2019-04-21
        • 2019-01-24
        • 2013-05-24
        • 1970-01-01
        • 1970-01-01
        • 2019-03-25
        相关资源
        最近更新 更多