Playframework: 2.5.3 “IO error while decoding Routes.scala with UTF-8” when compiling Play Framework project

Created on 11 May 2016  ·  4Comments  ·  Source: playframework/playframework

In my project, we have some Chinese comments in routes. But when we try to compile the source code, Play throws the following errors

[error] IO error while decoding Routes.scala with UTF-8

[error] Please try specifying another one using the -encoding option

[error] one error found

[error] (demo/compile:compileIncremental) Compilation failed

[error] Total time: 4 s, completed 2016-5-11 11:00:05

test routes is

#优惠包编辑
GET         /coupon/promotionCode/edit/:id               coupon.PromotionCodeApplication.edit(id:String)

after compile, the Routes.scala

 "GET",
      """@(优惠管理,优包惠编�?, coupon.group.edit)""",
      this.prefix + """coupon/group/edit/""" + "$" + """id<[^/]+>"""

Most helpful comment

@evandu I think I know what the problem is. The routes compiler is using the default system encoding, which is what the JVM uses, but you are explicitly setting UTF-8 for just the scala compiler. What you can do is set the environment variable:

JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8"

That will tell Java to use UTF-8 as the default encoding in the JVM.

I'm not sure this is something we can/should fix in Play. Unfortunately the scala compiler and java have two different ways of setting the encoding, and you have to make sure those are consistent.

All 4 comments

Hi @evandu,

Is the routes file encoded as UTF-8? If so, can you provide a small sample project showing the error?

Hi @gmethvin

sample project

thanks

@evandu I think I know what the problem is. The routes compiler is using the default system encoding, which is what the JVM uses, but you are explicitly setting UTF-8 for just the scala compiler. What you can do is set the environment variable:

JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8"

That will tell Java to use UTF-8 as the default encoding in the JVM.

I'm not sure this is something we can/should fix in Play. Unfortunately the scala compiler and java have two different ways of setting the encoding, and you have to make sure those are consistent.

Thanks a lot

Was this page helpful?
0 / 5 - 0 ratings