NutzCN Logo
问答 使用maven-shade-plugin打包遇到问题
发布于 2411天前 作者 qq_669c7635 12133 次浏览 复制 上一个帖子 下一个帖子
标签:

项目用的nutzboot,并采用的最新版本2.1.8
使用maven-shade-plugin打包遇到下列错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.1.1:shade (default) on projec        
t qqbs-nb-bweb: Error creating shaded jar: Invalid signature file digest for Manifest main attributes -> [        
Help 1]                                                                                                           
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:ma        
ven-shade-plugin:3.1.1:shade (default) on project qqbs-nb-bweb: Error creating shaded jar: Invalid signatu        
re file digest for Manifest main attributes                                                                       
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)                        
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)                        
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)                        
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.        
java:117)                                                                                                         
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.        
java:81)                                                                                                          
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleTh        
readedBuilder.java:51)                                                                                            
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)                
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)                                         
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)                                         
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)                                           
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)                                               
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)                                                
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)                                                  
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                            
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                          
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                  
        at java.lang.reflect.Method.invoke(Method.java:498)                                                       
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)                    
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)                            
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)                  
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)                              
Caused by: org.apache.maven.plugin.MojoExecutionException: Error creating shaded jar: Invalid signature fi        
le digest for Manifest main attributes                                                                            
        at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:546)                              
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:13        
4)                                                                                                                
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)                        
        ... 20 more                                                                                               
Caused by: 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.getInputStream(JarFile.java:450)                                                 
        at org.apache.maven.plugins.shade.DefaultShader.goThroughAllJarEntriesForManifestTransformer(Defau        
ltShader.java:291)                                                                                                
        at org.apache.maven.plugins.shade.DefaultShader.shade(DefaultShader.java:100)                             
        at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:442)                              
        ... 22 more                                                                                               

POM文件是这样配置的:

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                    <useIncrementalCompilation>false</useIncrementalCompilation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.0.0</version>

            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <mainClass>cn.wizzer.app.web.run.BwebMainLauncher</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/nutz/org.nutz.boot.starter.NbStarter</resource>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>cn.wizzer.app.web.run.BwebMainLauncher</mainClass>
                                </transformer>
                            </transformers>
			    
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

百度/Bing/Google了网上所有的资料,问题没解决,请大神指点一下,谢谢!

6 回复

有个jar文件损坏了

报错之前的日志里面,应该有提示.

PS: 新版建议用nutzboot-maven-plugin

@wendal 谢谢兽总,我用nutzboot-maven-plugin试试看

换了一样报错,关键是找出哪个jar损坏了

我们经过排查,发现项目引入的一个依赖有问题:

            <dependency>
                <groupId>bouncycastle</groupId>
                <artifactId>bcprov-jdk16</artifactId>
                <version>140</version>
            </dependency>

在POM文件去掉这个配置就可以了,下一步就是在打包服务器把bcprov-jdk16-140.jar文件放到${JAVA_HOME}/jre/lib/ext目录下去,就解决了问题

我们使用的JDK 1.8.0_171 MAVEN版本3.5.0
特意记录下这个特殊的问题,
@wendal 谢谢兽总的指点

微信小程序的签名? jdk8自带算法,不需要加这个jar了

添加回复
请先登陆
回到顶部