使用java命令出现Error: A JNI error has occurred, please check your installation and try again的错误
暂发现有两种原因,仔细看后面的报错信息
1、jdk版本不匹配
Exception in thread “main” java.lang.UnsupportedClassVersionError: helloworld has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0
发现为java与javac版本不一致而造成的,更换为一致之后重新编译打包
2、Invalid signature file digest for Manifest main attributes–文件签名不合法
这是因为在使用Maven打包的时候导致某些包的重复引用,以至于打包之后的META-INF的目录下多出了一些*.SF,.DSA,.RSA文件所致
如果使用maven打包则可以在pom.xml加上如下配置
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</build>
如果用的是idea来打包 的
可以通过解压工具打开,删除META-INF的目录下的*.SF,.DSA,.RSA文件,即可