解决maven控制台出现乱码情况

"C:\Program Files\Java\jdk-10.0.2\bin\java.exe" -Dmaven.multiModuleProjectDirectory=H:\maven_web -Dmaven.home=H:\Maven\apache-maven-3.5.2 -Dclassworlds.conf=H:\Maven\apache-maven-3.5.2\bin\m2.conf "-javaagent:H:\idea\IntelliJ IDEA 2018.3\lib\idea_rt.jar=54564:H:\idea\IntelliJ IDEA 2018.3\bin" -Dfile.encoding=UTF-8 -classpath H:\Maven\apache-maven-3.5.2\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2018.3 tomcat:run
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building maven_web Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) > compile @ maven_web >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven_web ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory H:\maven_web\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven_web ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to H:\maven_web\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] ����֧��Դѡ�� 5����ʹ�� 6 ����߰汾��
[ERROR] ����֧��Ŀ��ѡ�� 1.5����ʹ�� 1.6 ����߰汾��
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.172 s
[INFO] Finished at: 2019-06-23T22:32:27+08:00
[INFO] Final Memory: 12M/50M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project maven_web: Compilation failure: Compilation failure: 
[ERROR] ����֧��Դѡ�� 5����ʹ�� 6 ����߰汾��
[ERROR] ����֧��Ŀ��ѡ�� 1.5����ʹ�� 1.6 ����߰汾��
[ERROR] -> [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/MojoFailureException

Process finished with exit code 1

解决:maven默认环境为jdk,只需要改如下即可:
在IDEA中,打开File | Settings | Build, Execution, Deployment | Build Tools | Maven | Runner在VM Options中
添加-Dfile.encoding=GBK,切记一定是GBK。即使用UTF-8的话,依然是乱码,这是因为Maven的默认平台编码是GBK,
如果你在命令行中输入mvn -version的话,会得到如下信息,根据Default locale可以看出

### 解决Maven控制台乱码问题 #### 方法一:通过IDEA配置解决乱码 在IntelliJ IDEA中,可以通过调整Maven的运行参数来解决乱码问题。具体操作如下: 进入 `File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Runner` 页面,在 `VM options` 中添加 `-Dfile.encoding=GBK` 参数[^1]。 此方法适用于大多数情况下由于编码不一致引起的乱码问题。 --- #### 方法二:修改Tomcat日志文件编码 如果项目涉及Tomcat服务器,并且出现了中文乱码,则可能是Tomcat的日志编码未正确设置所致。可以尝试修改Tomcat的 `logging.properties` 文件,将其路径下的 `java.util.logging.ConsoleHandler.encoding` 属性值更改为 `GBK` 或其他适合项目的字符集编码[^2]。 例如,编辑位于 Tomcat 安装目录下 `\conf\logging.properties` 的文件内容为: ```properties java.util.logging.ConsoleHandler.encoding = GBK ``` --- #### 方法三:全局环境变量设置 除了局部配置外,还可以通过操作系统级别的环境变量来强制指定编码方式。对于Windows系统,可以在系统的高级属性中新增或更新以下环境变量: ```plaintext JAVA_TOOL_OPTIONS=-Dfile.encoding=GBK ``` 这种方式会作用于所有的Java程序实例上,因此需谨慎使用以防止影响到其他依赖UTF-8的应用场景[^3]。 --- #### 示例代码验证效果 为了确认更改后的编码设置生效与否,可编写一段简单的测试脚本用于打印带汉字字符串至控制台查看显示情况。 ```java public class EncodingTest { public static void main(String[] args) { System.out.println("你好,世界!"); System.out.println(System.getProperty("file.encoding")); } } ``` 当看到预期的文字正常呈现而非问号或其他异常符号时即表明当前设定已成功应用。 ---
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值