maven install时报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile,

maven install时报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile,出现编码GBK的不可映射字符。但是自己设置的项目及文件的编码格式均为utf-8.

【解决:】

 在maven的编译插件中声明正确的字符集编码编码——编译使用的字符集编码与代码文件使用的字符集编码一致!!
 
安装系统之后,一般中文系统默认字符集是GBK。我们安装的软件一般都继承使用操作系统的默认字符集。
 
所以在很多中文XP win7上开发的同学,在使用maven(mvn compile)编译项目的时候,就会出现“编码 gbk 的不可映射字符”: 
这个是由于代码使用的UTF-8,而maven编译的时候使用的GBK的缘故。 通过修改pom文件,可以告诉maven这个项目使用UTF-8来编译。

在pom的/project/build/plugins/下的编译插件声明 中加入下面的配置:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <build>  
  2.         <plugins>  
  3.             <plugin>  
  4.                 <artifactId>maven-compiler-plugin</artifactId>  
  5.                 <version>3.1</version>  
  6.                 <configuration>  
  7.                     <source>1.7</source>  
  8.                     <target>1.7</target>  
  9.                      <encoding>utf8</encoding>   
  10.                 </configuration>  
  11.             </plugin>  
  12.         </plugins>  
  13.     </build>  

maven项目出错,代码没有错
Run Maven4MyEclipse->Update Project or use Quick Fix. (或者按Alt+F5)

猜你喜欢

转载自blog.csdn.net/big_bigwolf/article/details/52291383