手上有个项目需要以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打包,再次运行之后问题解决~
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
名称栏目:Maven构建可运行的jar包出错解决办法-创新互联
文章起源:https://www.cdcxhl.com/article22/desicc.html
成都网站建设公司_创新互联,为您提供网站收录、品牌网站制作、Google、面包屑导航、企业网站制作、网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联