Maven遮阳罐抛出异常

时间:2011-11-28 20:41:30

标签: maven exception maven-shade-plugin

我有以下例外:

  

线程中的异常" main" java.lang.SecurityException:没有表现   签名文件条目部分   使用javax /安全/证书/ 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)           在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)           at sun.misc.URLClassPath $ JarLoader $ 2.getInputStream(URLClassPath.java:692)           at sun.misc.Resource.cachedInputStream(Resource.java:61)           在sun.misc.Resource.getByteBuffer(Resource.java:144)           at java.net.URLClassLoader.defineClass(URLClassLoader.java:256)           at java.net.URLClassLoader.access $ 000(URLClassLoader.java:58)           在java.net.URLClassLoader $ 1.run(URLClassLoader.java:197)           at java.security.AccessController.doPrivileged(Native Method)           在java.net.URLClassLoader.findClass(URLClassLoader.java:190)           at java.lang.ClassLoader.loadClass(ClassLoader.java:306)           在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:301)           at 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>

3 个答案:

答案 0 :(得分:26)

SecurityException出现是因为你的一个依赖项是一个签名的jar。 当阴影插件重新打包这个jar时,它会变得无效。 - &GT;发起时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

答案 1 :(得分:2)

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

答案 2 :(得分:0)

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

  

无法找到主类:com.mainClass。

在调用插件之前,可能没有编译类名或类中的拼写错误?