You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot Maven项目编译遇MalformedInputException错误求助

解决Maven resources-plugin过滤时的MalformedInputException错误

问题根源

该错误是由于application-test.properties文件的编码与Maven资源插件执行过滤操作时使用的编码不匹配,导致插件无法正确解析文件内容,触发了单字节非法输入的异常。

可行解决方案

1. 统一properties文件编码为UTF-8

确保目标配置文件以UTF-8编码保存:

  • IDEA环境:右键文件 → 打开"File Encodings"设置,将该文件编码设为UTF-8,同时勾选"Transparent native-to-ascii conversion"(处理中文等特殊字符的转义)。
  • 其他编辑器:直接将文件编码转换为UTF-8后重新保存。

2. 配置Maven资源插件编码

在项目pom.xml中明确指定资源插件的编码,与文件编码保持一致:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </plugin>
    </plugins>
</build>

3. 清理并指定编码重新编译

执行以下Maven命令,彻底清理后带编码参数重新构建:

mvn clean install -Dfile.encoding=UTF-8

-Dfile.encoding=UTF-8参数用于统一Maven运行时的系统编码。

4. 排查文件中的特殊字符

若以上方法无效,检查application-test.properties中是否存在不可见的特殊字符(如全角空格、控制字符),可通过编辑器的"显示所有字符"功能排查并删除异常字符后重试。

内容的提问来源于stack exchange,提问作者faDev1998

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 06:47:36