下面是使用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. JavaScript中如何判断两变量是否“相等”?

    1 为什么要判断? 可能有些同学看到这个标题就会产生疑惑,为什么我们要判断JavaScript中的两个变量是否相等,JavaScript不是已经提供了双等号“==”以及三等号“===”给我们使用了吗? ...

  2. ezmorph-1.0.6.jar的作用

    使用json时要依赖的jar文件,在使用jquery的json时,没有引用该文件的时候容易报错.

  3. 简易log4j 父logger和子logger

    log4j 父logger和子logger         定义子logger其目的就是能够在某一范围内(某一个class或者某一个package)下面,日志的输出方式与其他地方的日志输出方式不同. ...

  4. [cocos2d-x]-会动的精灵

    小鸟一直在扑翅膀的代码块: auto sprite = Sprite::create(); Animation *animation = Animation::create(); animation- ...

  5. 程序中实现两个DataTable的Left Join效果(修改了,网上第二个DataTable为空,所处的异常)

    public static DataTable Join(DataTable First, DataTable Second, DataColumn[] FJC, DataColumn[] SJC) ...

  6. Perl中的字符串操作函数

    1.$position = index(string,substring,skipchars): 该函数返回子串substring在字符串string中的位置,如果不存在,则返回-1:参数skipch ...

  7. UVa 1625 - Color Length(线性DP + 滚动数组)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. Cocos2dx打包apk时变更NDK引发问题及解决

    现在官方的Cocos Studio已经支持打包apk文件,写该随笔的时候还没试过官方的打包功能,所以就按自己的学习顺序先把打包的心得写下. 问题及最终解决方案: 其中耗时最长的问题就是ndk-r10改 ...

  9. Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】

    任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...

  10. 8.spring:事务管理(上):Spring的数据库编程、编程式事务管理

    Spring的数据库编程 Spring框架提供了JDBC模板模式------>JdbcTemplate 简化了开发,在开发中并不经常是使用 实际开发更多使用的是Hibernate和MyBatis ...