zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources和如何修改idea的默认编码

MavenApacheIDEA编码Failed 如何 to 修改
2023-09-14 09:07:25 时间

今天使用idea创建完一新项目后,将其他项目的application.properties文件里的数据拷贝到当前项目的application.properties中。

执行mvn -clean没事有问题,但执行mvn install便出现如下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project superjsonmanager: 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

参考网上的资料,需要在pom.xml文件中添加如下代码:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.2.0</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.shared</groupId>
            <artifactId>maven-filtering</artifactId>
            <version>3.2.0</version>
        </dependency>
    </dependencies>
</plugin>

添加以上代码后,依旧报错,于是再次去看错误信息。
错误信息根据错误提示信息可以看出,让我们使用UT-8的编码格式,于是,去查询idea如何设置编码格式,即file -> settings -> editor -> file editor -> file encodings ,查看原格式是什么?
idea默认编码
从图中可以看到,idea默认编码格式为GBK,因而,我们拷贝过来的数据出现了编码格式的错误,于是,按照如下方式修改即可:
修改编码的截图
修改完成后,重新启动项目,还是报出上诉的错误,查找原因后知道,原来修改完编码后,application.properties文件出现了乱码:
编码修改后的乱码文件
于是修改乱码:
修改乱码文件
修改之后,重新执行 mvn -celan mvn -install,便能正常install了,如图所示:
在这里插入图片描述