如何使用Maven shade插件修复“ZLIB输入流的意外结束”?

时间:2012-10-02 09:30:09

标签: maven

运行Maven Shade插件时,出现以下错误。我该怎么调试呢?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.0:shade (make-shade) on project csprocessor-client: Error creating shaded jar: Unexpected end of ZLIB input stream -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.0:shade (make-shade) on project csprocessor-client: Error creating shaded jar: Unexpected end of ZLIB input stream
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error creating shaded jar: Unexpected end of ZLIB input stream
    at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:551)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream
    at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:411)
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at org.codehaus.plexus.util.IOUtil.copy(IOUtil.java:188)
    at org.codehaus.plexus.util.IOUtil.copy(IOUtil.java:174)
    at org.apache.maven.plugins.shade.DefaultShader.addRemappedClass(DefaultShader.java:259)
    at org.apache.maven.plugins.shade.DefaultShader.shade(DefaultShader.java:151)
    at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:484)
    ... 21 more
[ERROR] 
[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/MojoExecutionException

2 个答案:

答案 0 :(得分:1)

事实证明,使用m2eclipse插件,您可以在执行时实际调试maven插件。要执行此操作,您需要使用要进入的代码,您可以通过在Maven运行配置中设置调试输出选项来执行此操作。您还需要设置解析工作区工件选项。

enter image description here

使用这两个选项,我可以单击错误中列出的文件位置(在本例中为ZipFile.java:411),设置断点,并使用 Debug As> Maven Build 以在调试模式下运行Maven构建。一旦断点被​​击中,我可以判断哪个文件导致错误,并使用JAR command重新打包它。即使可以使用GUI归档工具打开相关的JAR文件,一旦使用JAR命令重新打包,我就可以成功运行Maven Shade plgin。

答案 1 :(得分:0)

仅供参考,如果这是由下载过程中损坏的JAR引起的,则强制重新下载的快速方法是在着色项目中运行mvn dependency:purge-local-repository。来自本地Maven存储库的项目removes all dependencies(直接和传递)并重新下载。