maven命令报错怎么解决(maven编译遇到)
maven命令报错怎么解决(maven编译遇到)
环境- 操作系统:win10
- JDK:1.8.0_144
- maven:3.5.0
- 普通的 maven 工程,JAVA 源码注释中有中文,如下:
package com.bolingcavalry.addservice;
/**
* @author wilzhao
* @description 加法服务对应的接口
* @email zq2599@gmail.com
* @time 2018/10/13 10:07
*/
public interface AddService {
int add(int a int b);
}
- 使用下面的命令编译:
mvn clean compile -Dmaven.test.skip=true
- 虽然提示编译成功,但是有警告编码 GBK 的不可映射字符,如下所示:
[WARNING] /C:/temp/201810/07/customizestarter/addservice/src/main/java/com/bolingcavalry/addservice/AddService.java:
[5 30] 编码GBK的不可映射字符
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.853 s
[INFO] Finished at: 2018-10-13T11:07:16 08:00
[INFO] Final Memory: 13M/162M
[INFO] ------------------------------------------------------------------------
- maven 用的是 win10 的字符集,在 winndows 命令行输入 chcp,返回 936 表示 GBK,如下图:
- 而 JAVA 的字符集是 UTF8,所以只要把 maven 编译时的字符集改为 UTF8 即可;
- 在 pom.xml 的属性节点中增加属性:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
- 整体效果如下图,红色是新增内容:
- 再编译,这次没有警告了:
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ addservice ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\temp\201810\07\customizestarter\addservice\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.332 s
[INFO] Finished at: 2018-10-13T11:28:40 08:00
[INFO] Final Memory: 13M/163M
[INFO] ------------------------------------------------------------------------