温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Maven构建可运行的jar包出错解决办法

发布时间:2020-07-15 10:38:20 来源:网络 阅读:385 作者:沙漏半杯 栏目:编程语言

手上有个项目需要以jar方式运行,使用maven-shade-plugin插件构建成功后,在服务器上运行"nohup java -jar myProject.jar > /dev/null &"出错,错误信息:“Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes”,网上搜索了半天,发现一个解决办法:  http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar


在pom文件maven-shade-plugin插件的配置信息中添加:



<configuration>

    <filters>

        <filter>

            <artifact>*:*</artifact>

            <excludes>

                <exclude>META-INF/*.SF</exclude>

                <exclude>META-INF/*.DSA</exclude>

                <exclude>META-INF/*.RSA</exclude>

            </excludes>

        </filter>

    </filters>

    <!-- Additional configuration. -->

</configuration>

继续运行,之前的错误解决了,却提示新的错误:“Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context] Offending resource: class path resource [applicationContext.xml]”


解决办法是在构建的时候加入META-INF/spring.schemas 和 META-INF/spring.handlers transformers,最终的maven-shade-plugin插件信息配置如下:


<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-shade-plugin</artifactId>

<version> 1.7.1</version>

<executions>

<execution> 

<phase>package</phase>

<goals>

<goal>shade</goal>

</goals>

<configuration>

<filters>

        <filter>

            <artifact>*:*</artifact>

            <excludes>

                <exclude>META-INF/*.SF</exclude>

                <exclude>META-INF/*.DSA</exclude>

                <exclude>META-INF/*.RSA</exclude>

            </excludes>

        </filter>

    </filters>

<transformers>

<transformer

implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">

<resource>META-INF/spring.handlers</resource>

</transformer>

<transformer

implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">

<resource>META-INF/spring.schemas</resource>

</transformer>

<transformer

implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

<mainClass>com.zhilin.paopao.server.NIOServer</mainClass>

</transformer>

</transformers>

</configuration>

</execution>

</executions>

</plugin>


重新clean install打包,再次运行之后问题解决~


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI