欢迎访问我的GitHub
这里分类和汇总了欣宸的全部原创(含配套源码):
https://github.com/zq2599/blog_demos
环境
- 操作系统: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即可;
解决办法
<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] ------------------------------------------------------------------------
欢迎关注阿里云开发者社区博客:程序员欣宸
学习路上,你不孤单,欣宸原创一路相伴...