Maven shade jar throw exception

后端 未结 3 817
小鲜肉
小鲜肉 2020-12-06 02:02

I have the following Exception:

Exception in thread \"main\" java.lang.SecurityException: no manifiest section for signature file entry javax

相关标签:
3条回答
  • 2020-12-06 02:41

    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?

    0 讨论(0)
  • 2020-12-06 02:46

    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

    0 讨论(0)
  • 2020-12-06 02:46

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

    0 讨论(0)
提交回复
热议问题