# Java Maven 编译资源文件拷贝错误 dirCompressed.zip failed with MalformedInputException:

**URL:** <https://www.isharkfly.com/t/java-maven-dircompressed-zip-failed-with-malformedinputexception/15694>\
**Category:** 程序语言\
**Tags:** java, maven\
**Created:** [April 30, 2024, 9:52pm UTC](https://www.isharkfly.com/t/java-maven-dircompressed-zip-failed-with-malformedinputexception/15694 "2024-04-30T21:52:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [April 30, 2024, 9:52pm UTC](https://www.isharkfly.com/t/java-maven-dircompressed-zip-failed-with-malformedinputexception/15694/1 "2024-04-30T21:52:54Z")

</div>

完整的错误信息为：

```auto
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.3.1:resources (default-resources) on project core-java-io: filtering C:\WorkDir\Repository\iSharkfly-Docs\java-tutorials\core-java-modules\core-java-io\src\main\resources\dirCompressed.zip to C:\WorkDir\Repository\iSharkfly-Docs\java-tutorials\core-java-modules\core-java-io\target\classes\dirCompressed.zip failed with MalformedInputException: Input length = 1 -> [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/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <args> -rf :core-java-io

```

 ![2024-04-30_17-50-20](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/2X/a/a15ab18f084f5dab20b7664fc06130a23e24db10.png)

## 问题和解决

出现上面错误的原因是在资源文件进行拷贝的时候的校验问题。

我们需要拷贝一个 zip 的资源文件，但是 Maven 在拷贝的时候会进行校验，这会导致拷贝失败。

所以我们可以添加配置：

```xml
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>zip</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>

```

到 插件 maven-resources-plugin 中。

添加后的完整插件配置为：

```xml
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>${maven-resources-plugin.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>zip</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>

```

 ![2024-04-30_17-52-22](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/2X/d/da12a5613a0f73d7a34383c86436fc88fe412879.png)

当完成上面的配置后，资源文件就可以顺利在编译的时候拷贝了。
