mvn打包文件签名不合法问题

问题现象

$ java -jar target/x.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
    at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:330)
    at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:263)
    at java.util.jar.JarVerifier.processEntry(JarVerifier.java:318)
    at java.util.jar.JarVerifier.update(JarVerifier.java:230)
    at java.util.jar.JarFile.initializeVerifier(JarFile.java:383)
    at java.util.jar.JarFile.ensureInitialization(JarFile.java:612)
    at java.util.jar.JavaUtilJarAccessImpl.ensureInitialization(JavaUtilJarAccessImpl.java:69)
    at sun.misc.URLClassPath$JarLoader$2.getManifest(URLClassPath.java:991)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:451)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

原因

因为在使用Maven打包的时候导致某些包的重复引用,以至于打包之后的META-INF的目录下多出了一些*.SF,.DSA,.RSA文件所致。

例如:

./META-INF$ ls
BCKEY.DSA  BCKEY.SF  DEPENDENCIES  LICENSE  MANIFEST.MF  NOTICE  io.netty.versions.properties  maven  native  services  spring.provides  versions

包含BCKEY.DSA BCKEY.SF

解决方法

删除jar包中的意外文件

zip -d your.jar 'META-INF/*.SF' 'META-INF/*.RSA' 'META-INF/*.DSA' 

mvn 过滤文件

我们可以在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>
</configuration>

诊断mvn package dependecy方法

诊断package重复使用mvn dependency:tree -Dverbose

$ mvn dependecy:tree -Dverbose 
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.mheartcube:game-server:jar:1.2-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 87, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 kB at 16 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 kB at 10 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.986 s
[INFO] Finished at: 2019-05-20T17:18:27+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'dependecy' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/guangfuhe/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

# guangfuhe @ guangfudeMacBook-Pro in ~/Project/learn/java/gameserver on git:master x [17:18:27] C:1
$ mvn dependency:tree -Dverbose                                            
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.mheartcube:game-server:jar:1.2-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 87, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] ---------------------< com.mheartcube:game-server >---------------------
[INFO] Building game-server 1.2-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ game-server ---
[INFO] com.mheartcube:game-server:jar:1.2-SNAPSHOT
[INFO] +- io.netty:netty-all:jar:4.1.27.Final:compile
[INFO] +- io.jpower.kcp:kcp-netty:jar:1.4.2:compile
[INFO] |  \- io.netty:netty-transport:jar:4.1.27.Final:compile
[INFO] |     +- io.netty:netty-buffer:jar:4.1.27.Final:compile
[INFO] |     |  \- io.netty:netty-common:jar:4.1.27.Final:compile
[INFO] |     \- io.netty:netty-resolver:jar:4.1.27.Final:compile
[INFO] |        \- (io.netty:netty-common:jar:4.1.27.Final:compile - omitted for duplicate)
[INFO] +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.6.RELEASE:compile
[INFO] |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.25:compile - omitted for duplicate)
[INFO] |  |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |     \- (org.slf4j:slf4j-api:jar:1.7.25:compile - omitted for duplicate)
[INFO] +- com.google.protobuf:protobuf-java:jar:3.6.1:compile
[INFO] +- junit:junit:jar:4.12:compile
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] +- io.jsonwebtoken:jjwt-api:jar:0.10.5:compile
[INFO] +- io.jsonwebtoken:jjwt-impl:jar:0.10.5:compile
[INFO] |  \- (io.jsonwebtoken:jjwt-api:jar:0.10.5:compile - omitted for duplicate)
[INFO] +- io.jsonwebtoken:jjwt-jackson:jar:0.10.5:compile
[INFO] |  +- (io.jsonwebtoken:jjwt-api:jar:0.10.5:compile - omitted for duplicate)
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.9.6:compile
[INFO] |     +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] |     \- com.fasterxml.jackson.core:jackson-core:jar:2.9.6:compile
[INFO] \- org.bouncycastle:bcpkix-jdk15on:jar:1.52:compile
[INFO]    \- org.bouncycastle:bcprov-jdk15on:jar:1.52:compile

--Posted from Rpc

转载于:https://my.oschina.net/hgfdoing/blog/3051877

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值