cmd窗口下执行jar包 logger.info输出乱码,out语句输出正常解决办法

Posted 健康平安的活着

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cmd窗口下执行jar包 logger.info输出乱码,out语句输出正常解决办法相关的知识,希望对你有一定的参考价值。

一 问题描述

执行jar包,在cmd窗口中执行jar包,看到输出中,logger.info的输出为乱码,而System.out.println()输出为正确的日志。

二 解决办法

1.因为cmd默认的编码为GBK,jar包一般设置为UTF-8;

2.在cmd窗口先输入:

2.1 chcp 65001  (注意之间有空格

2.2 然后执行jar包命令:E:\\huadian-project\\fan_intelligent_server\\target>java -jar -Dfile.encoding=utf-8 fanintelligent.jar

Active code page: 65001

E:\\huadian-project\\fan_intelligent_server\\target>java -jar -Dfile.encoding=utf-8 fanintelligent.jar

  .   ____          _            __ _ _
 /\\\\ / ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\
( ( )\\___ | '_ | '_| | '_ \\/ _` | \\ \\ \\ \\
 \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.2)

2021-06-02 22:28:37.570  INFO 5632 --- [           main] com.bonc.smartpower.fanintelligent.App   : Starting App v0.0.1-SNAPSHOT using Java 1.8.0_181 on LAPTOP-VC53HCIP with PID 5632 (E:\\huadian-project\\fan_intelligent_server\\target\\fanintelligent.jar started by jurfl in E:\\huadian-project\\fan_intelligent_server\\target)
2021-06-02 22:28:37.574  INFO 5632 --- [           main] com.bonc.smartpower.fanintelligent.App   : No active profile set, falling back to default profiles: default
2021-06-02 22:28:42.119  INFO 5632 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-06-02 22:28:43.135  INFO 5632 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 996 ms. Found 13 JPA repository interfaces.
2021-06-02 22:28:46.605  INFO 5632 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-06-02 22:28:46.621  INFO 5632 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-06-02 22:28:46.621  INFO 5632 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-06-02 22:28:46.768  INFO 5632 --- [           main] o.a.c.c.C.[.[.[/fanIntelligentServer]    : Initializing Spring embedded WebApplicationContext
2021-06-02 22:28:46.768  INFO 5632 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 8891 ms
2021-06-02 22:28:47.063  INFO 5632 --- [           main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2021-06-02 22:28:47.561  INFO 5632 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
2021-06-02 22:28:47.907  INFO 5632 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-06-02 22:28:48.149  INFO 5632 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.27.Final
2021-06-02 22:28:48.461  INFO 5632 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-06-02 22:28:49.075  INFO 5632 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.mysql57Dialect
2021-06-02 22:28:50.278  INFO 5632 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-06-02 22:28:50.295  INFO 5632 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-06-02 22:28:53.080  WARN 5632 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-06-02 22:28:53.414  INFO 5632 --- [           main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]
2021-06-02 22:28:53.776  INFO 5632 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-06-02 22:28:54.416  INFO 5632 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
2021-06-02 22:28:54.545  INFO 5632 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path '/fanIntelligentServer'
2021-06-02 22:28:54.546  INFO 5632 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2021-06-02 22:28:54.585  INFO 5632 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2021-06-02 22:28:54.706  INFO 5632 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
2021-06-02 22:28:55.028  WARN 5632 --- [           main] s.d.s.w.r.p.ParameterDataTypeReader      : Trying to infer dataType java.lang.String[]
2021-06-02 22:28:55.029  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: updateMonitorStateUsingGET_1
2021-06-02 22:28:55.030  WARN 5632 --- [           main] s.d.s.w.r.p.ParameterDataTypeReader      : Trying to infer dataType java.lang.String[]
2021-06-02 22:28:55.033  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: updateMonitorStateUsingHEAD_1
2021-06-02 22:28:55.034  WARN 5632 --- [           main] s.d.s.w.r.p.ParameterDataTypeReader      : Trying to infer dataType java.lang.String[]
2021-06-02 22:28:55.035  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: updateMonitorStateUsingPOST_1
2021-06-02 22:28:55.036  WARN 5632 --- [           main] s.d.s.w.r.p.ParameterDataTypeReader      : Trying to infer dataType java.lang.String[]
2021-06-02 22:28:55.037  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: updateMonitorStateUsingPUT_1
2021-06-02 22:28:55.038  WARN 5632 --- [           main] s.d.s.w.r.p.ParameterDataTypeReader      : Trying to infer dataType java.lang.String[]
2021-06-02 22:28:55.042  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: updateMonitorStateUsingPATCH_1
2021-06-02 22:28:55.044  WARN 5632 --- [           main] s.d.s.w.r.p.ParameterDataTypeReader      : Trying to infer dataType java.lang.String[]
2021-06-02 22:28:55.045  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: updateMonitorStateUsingDELETE_1
2021-06-02 22:28:55.046  WARN 5632 --- [           main] s.d.s.w.r.p.ParameterDataTypeReader      : Trying to infer dataType java.lang.String[]
2021-06-02 22:28:55.048  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: updateMonitorStateUsingOPTIONS_1
2021-06-02 22:28:55.049  WARN 5632 --- [           main] s.d.s.w.r.p.ParameterDataTypeReader      : Trying to infer dataType java.lang.String[]
2021-06-02 22:28:55.052  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: updateMonitorStateUsingTRACE_1
2021-06-02 22:28:55.224  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: exportFanAlarmListUsingGET_1
2021-06-02 22:28:55.232  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: getfanDeviceInfoUsingGET_1
2021-06-02 22:28:55.232  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: getfanDeviceInfoUsingHEAD_1
2021-06-02 22:28:55.233  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: getfanDeviceInfoUsingPOST_1
2021-06-02 22:28:55.234  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: getfanDeviceInfoUsingPUT_1
2021-06-02 22:28:55.234  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: getfanDeviceInfoUsingPATCH_1
2021-06-02 22:28:55.235  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: getfanDeviceInfoUsingDELETE_1
2021-06-02 22:28:55.237  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: getfanDeviceInfoUsingOPTIONS_1
2021-06-02 22:28:55.239  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: getfanDeviceInfoUsingTRACE_1
2021-06-02 22:28:55.243  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: queryFanListInfoUsingPOST_1
2021-06-02 22:28:55.312  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: selectDeviceUsingGET_1
2021-06-02 22:28:55.312  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: selectDeviceUsingHEAD_1
2021-06-02 22:28:55.314  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: selectDeviceUsingPOST_1
2021-06-02 22:28:55.315  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: selectDeviceUsingPUT_1
2021-06-02 22:28:55.317  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: selectDeviceUsingPATCH_1
2021-06-02 22:28:55.318  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: selectDeviceUsingDELETE_1
2021-06-02 22:28:55.319  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: selectDeviceUsingOPTIONS_1
2021-06-02 22:28:55.320  INFO 5632 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: selectDeviceUsingTRACE_1
2021-06-02 22:28:55.418  INFO 5632 --- [           main] com.bonc.smartpower.fanintelligent.App   : Started App in 18.908 seconds (JVM running for 19.783)
2021-06-02 22:28:55.423  INFO 5632 --- [           main] com.bonc.smartpower.fanintelligent.App   : =====================华电智能预警服务启动成功===============!!!!!!!
=====================华电智能预警服务启动成功===============!!!!!!!

3.如果还是乱码的话,需要修改字体:

在命令行标题栏上点击右键,选择"属性"->"字体",将字体修改为True Type字体"Lucida Console",然后点击确定将属性应用到当前窗口。如下图所示:

总结:之前项目遇到乱码,就是按照上面步骤进行了解决。

以上是关于cmd窗口下执行jar包 logger.info输出乱码,out语句输出正常解决办法的主要内容,如果未能解决你的问题,请参考以下文章

cmd怎么执行OneClick.jar

将Spring源码转换为工程 + 导入Eclipse时缺失jar包

纯手工打jar 包

android studio打可执行jar包

怎样在cmd中,将java打包为jar包~

自己手动maven命令将jar包安装到本地。