windows上cli 处理文件编码问题
cashtang opened this issue · comments
openapi yaml 文件有中文字符,文件编码格式是 utf-8 。当在windows cmd 下执行时会提示编码错误,需要加上 -Dfile.encoding=UTF-8。
错误信息如下:
`java -jar bin/cli-0.2.0-SNAPSHOT.jar checkstyle -r style-check-rules.properties -f openapi.yml
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.RuntimeException: java.io.CharConversionException: Invalid UTF-8 start byte 0xb5 (at char #35, byte #-1)
at [Source: (byte[])"openapi: '3.0.2'
info:
title: ?????POS???
version: '1.0.0'
description: ???POS???????
servers:
- url: 'https://xxxxxxxx'
description: ???????????????
- url: http://xxxxxxxxxx/{basePath}
description: ?????????????
variables:
basePath:
default: v2
description: api version
paths:
/pos/login.init:
$ref: commonapi.yml#/components/login.init
/pos/login:
$ref: commonapi.yml#/compo"[truncated 1336 bytes]; line: 1, column: 1]
at org.apache.servicecomb.toolkit.cli.CheckStyleBase.run(CheckStyleBase.java:84)
at org.apache.servicecomb.toolkit.cli.ToolkitMain.main(ToolkitMain.java:48)
... 8 more
make: *** [Makefile:28: verify] Error 1`
谢谢提出问题,如果方便的话要不要提交个PR来修复这个问题?
先按照这个文章的方式,在这里注册个账号,然后提交个JIRA
http://servicecomb.apache.org/cn/developers/use-jira/
按照这里准备好开发环境,主要是设置代码风格:
http://servicecomb.apache.org/cn/developers/setup-develop-environment/
按照这里提出的方法创建PR
http://servicecomb.apache.org/cn/developers/submit-codes/
@chanjarster 可以给一下这个问题解决方案建议吗?
@WillemJiang 我觉得在读取文件的地方要显式的使用UTF作为编码格式,而不是让JDK采用平台默认的编码格式,这样就能解决问题了。
@WillemJiang 我觉得在读取文件的地方要显式的使用UTF作为编码格式,而不是让JDK采用平台默认的编码格式,这样就能解决问题了。
我看了一下代码,读取文件用的是 commons.io FileUtils 读取的,并且指定了 utf-8 字符集。估计是Swegger 的 parseYaml 错误了。
@cashtang 我看了代码,似乎调用路径上都已经设置了UTF8编码格式。
另:我找了台Windows试了一下,拿的是 style.yaml 没有复现你说的问题。
你能拿这个文件在你的windows上试试看有没有问题吗?