下面是使用Intellij 打包jar文件的步骤,之后会有运行jar文件时遇到的错误。

打包完成。

==========================================================================

运行jar出现问题:

1、找不到主类。打开jar文件包,在MANIFEST.MF文件中添加Main-Class:  包名.类名,

注意:包名前面有空格,类名没有.java或者.class后缀,最后一定要回车到下一行。让光标定位在空白行。

打开

2、java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

打开META-INF目录,将*.SF,*.DSA,*.RSA文件删除,即可。应为有些包有签名,导致错误。

此问题,可以参考下面的连接,这位大神比较详细,http://www.cnblogs.com/fuxinci/p/3356087.html,(如有侵权请告知,会删除,谢谢!)。

使用meaven打包过程中遇到的一些问题

 

开始使用如下代码进行打包

<build>
<!-- mvn assembly:assembly -Dmaven.test.skip=true -->
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.fxc.rpc.impl.member.MemberProvider</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

结果出现spring命名空间无法找到的错误,

org.xml.sax.SAXParseException: schema_reference.4: 无法读取方案文档 'http://www.springframework.org/schema/beans/spring-beans.xsd', 原因为 1) 无法找到文档; 2) 无法读取文档; 3) 文档的根元素不是 <xsd:schema>。

据查是由于spring-core,spring-aop每一个jar中都包含了一套spring.handlers,spring.schemas文件,以至于在打包过程中发生了覆盖,网上没有搜到使用maven-assembly-plugin插件如何解决此问题,大多数人建议使用maven-shade-plugin插件,修改后pom代码如下

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<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.ManifestResourceTransformer">
<mainClass>com.fxc.rpc.impl.member.MemberProvider</mainClass>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

再次打包,出现文件签名不合法的问题

Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

再查,原来是由于某些包的重复引用,以至于打包之后的META-INF的目录下多出了一些*.SF,*.DSA,*.RSA文件所致(据说解压jar包,然后删掉这些文件再次打包错误就会消失,未确认),再次修改pom.xml,最终使用如下配置文件,运行

mvn clean install -Dmaven.test.skip=true

打包成功

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</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.ManifestResourceTransformer">
<mainClass>com.fxc.rpc.impl.member.MemberProvider</mainClass>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

此时查看target目录下会发现xxx.jar 和original-xxx.jar,后一个不包含引用的jar包,直接运行前一个即可

java -jar target/xxx.jar 

成功!

PS:项目中使用了几个公司自己的jar,在公有库里没有,在eclipse里运行的时候我都是修改scope为system,调用的本地jar,但是在打包的过程中scope=system的jar是不会自己打进去的,很是让我郁闷,我只好讲这些jar安装进入本地资源库

mvn install:install-file -Dfile=my-jar.jar -DgroupId=org.richard -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar

Intellij打包jar文件,“java.lang.SecurityException: Invalid signature file digest for Manifest main attrib的更多相关文章

  1. 封装jar问题java.lang.SecurityException: Invalid signature file digest for Manifest main attributes以及maven依赖重提解决

    1.jar包封装完成后,其他项目引用jar,启动时报错java.lang.SecurityException: Invalid signature file digest for Manifest m ...

  2. idea的jar文件,“java.lang.SecurityException: Invalid signature file digest for Manifest main attribute

    感谢大佬:https://blog.csdn.net/mingyuli/article/details/84674483 命令行运行jar出现问题: 1.找不到主类.打开jar文件包,在MANIFES ...

  3. 执行打的maven jar包时出现“Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes”

    Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for ...

  4. 解决java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

    解决java.lang.SecurityException: Invalid signature file digest for Manifest main attributes 当项目依赖其他jar ...

  5. Ubuntu环境下java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

    一.问题描述 Ubuntu环境中,将maven项目打包成jar包传到服务器中后运行以下指令: $ java -cp my.jar com.myproject.Main 遇到报错: java.lang. ...

  6. spark提交任务报错: java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

    spark提交任务报错: java.lang.SecurityException: Invalid signature file digest for Manifest main attributes ...

  7. linux报错jar包时出现“Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes”

    linux安装zip命令: yum install zip zip -d demo.jar META-INF/*.RSA META-INF/*.DSA META-INF/*.SF

  8. Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest

    解决办法: 删除对应的jar 包下的文件 zip -d *.jar META-INF/*.RSA META-INF/*.SF

  9. Error- spark streaming 打包将全部依赖打进去Invalid signature file digest for Manifest main attributes

    spark streaming 打包将全部依赖打进去,运行jar包报错:如下 Exception in thread "main" java.lang.SecurityExcept ...

随机推荐

  1. CoreAnimation confusion: CATransaction vs CATransition vs CAAnimationGroup?

    http://stackoverflow.com/questions/14042755/coreanimation-confusion-catransaction-vs-catransition-vs ...

  2. 【转】 url中文乱码问题

    [转自]http://blog.csdn.net/rascalboy520/article/details/2511175 在URL中传递参数,是通过HTTP报头来传递的.并不是类似于通过表单来传递, ...

  3. 牛客网多校训练第一场 F - Sum of Maximum(容斥原理 + 拉格朗日插值法)

    链接: https://www.nowcoder.com/acm/contest/139/F 题意: 分析: 转载自:http://tokitsukaze.live/2018/07/19/2018ni ...

  4. 【[JLOI2013]卡牌游戏】

    思路太妙了 刚开始yy出了一种比较自然的dp方法,就是按照游戏的进行来开始dp,设\(dp[i][j]\)表示第\(i\)个人为庄家,还剩下\(j\)个人的概率为多少,但是很快发现这个样子没法转移,因 ...

  5. List环形双向链表

    实现一个环形的双向链表,链表的每个节点都保存三个信息,当前节点的值value,前一个节点的指针prev,后一个节点的指针next.因为是环形的,所以最后一个节点的next指向第一个节点,而第一个节点的 ...

  6. UVALive4682 XOR Sum

    UVALive4682 XOR Sum 题意 给定一个数组, 求连续子序列中异或值最大的值. 题解 假设答案区间为 [L, R], 则答案为 XOR[L, R], 可以将区间分解为 XOR[L,R] ...

  7. hdu 1010(迷宫搜索,奇偶剪枝)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...

  8. 过滤xss攻击脚本

    <?php /** * @blog http://www.phpddt.com * @param $string * @param $low 安全别级低 */ function clean_xs ...

  9. jquery特效 点击某项,其它隐藏

    <html> <head> </head> <body> <script> $(function(){ $(".cPage a&q ...

  10. Nginx负载均衡+代理+ssl+压力测试

    一.Tomcat安装 1.下载jdk,Tomcat,解压到/usr/local/ 2.配置jdk环境: # vim /etc/profile export JAVA_HOME=/usr/local/j ...