1

I'm using OpenLiberty (automatically downloaded through its maven plugin) and my application is working fine (jax-rs and servlet/jsp outputs are fine).

But the console (and messages.log) output is messy. Here is one example:

[INFORMAıåES] SRVE0253I: [io.openliberty.microprofile.health.3.0.internal] [/health] [HealthCheckServlet]: Destrui?Æo bem sucedida.

(expected is [INFORMAÇÕES] ... Destruição bem sucedida.)

Clearly the messages are being printed as ISO-8859-1 in a UTF-8 capable terminal.

Again, this question is not about the application running inside OpenLiberty container, which is completely UTF-8 and working fine. It is about the console output.

A partially useful workaround would be to change its locale to en-US (so that OpenLiberty's messages wouldn't need any special character). Actually, I'd prefer english error messages, because they are easier to google for.

I already tried LANG=en-US.UTF8, LC_ALL=en_US and LC_MESSAGES=en_US, to no avail.

Project's effective pom.xml already declares <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>. Every file in my project is UTF-8. Project's .editorconfig [*] charset = utf-8 (so vscode creates every new file as utf-8).

I'm using bash MINGW64_NT-10.0-18363 + ConEmu-Maximus5 over Windows 10. LANG defaults to =pt_BR.UTF-8.

UPDATE

I've managed to set locale to en-US by adding -Duser.language=en to ${server.config.dir}/jvm.options.

To be honest, I did it through liberty-maven-plugin:

  <properties>
    ...
    <liberty.jvm.language>-Duser.language=en-US</liberty.jvm.language>
    ...
  </properties>

(and for liberty-maven-plugin itself, I've added -Duser.language=en to MAVEN_OPTS)

Unfortunately, -Dfile.encoding=UTF-8 did nothing.

UPDATE 2

I'm also running OpenLiberty inside an Arquillian driven junit test. Interestingly, when launched by arquillian, OpenLiberty honors the -Dfile.encoding=utf-8 setting.

For arquillian it could be configured through arquillian.xml:

<arquillian ...>
    <container qualifier="liberty_managed" default="true">
        <configuration>
            ...
            <property name="javaVmArguments">-Dfile.encoding=utf-8</property>
            ...
        </configuration>
    </container>
</arquillian>

Or in ${server.config.dir}/jvm.options (as I did before):

-Dfile.encoding=utf-8

My conclusion is that -Dfile.encoding is the right way to approach this issue. But somehow when launched by liberty-maven-plugin it is not honored. I'll take a closer look into its source code.

rslemos
  • 2,454
  • 22
  • 32

1 Answers1

0

UPDATED ANSWER: This is configurable via JVM options.

Note that in general the jvm.options file requires you to use a single option per line.

If want to use multiple options and use liberty-maven-plugin properties to configure them you could do something like:

    <properties>
        <liberty.jvm.arg1>-Duser.language=pt</liberty.jvm.arg1>
        <liberty.jvm.arg2>-Duser.country=BR</liberty.jvm.arg2>
        <liberty.jvm.arg3>-Dfile.encoding=utf-8</liberty.jvm.arg3>
    </properties> 

(Note that the arg1,arg2,arg3 suffixes don't really get used except to assign unique Maven project property names, but don't appear in the jvm.options file).

And your terminal program must have support for displaying these characters. E.g. for me using the Git Bash default terminal with default settings on a US/English install, the characters in the above Portuguese language config don't display unless click the Window icon then "Options" and add this:

Select UTF-8 character set

Scott Kurz
  • 4,985
  • 1
  • 18
  • 40
  • Yes, the `-Duser.language=en` works in `jvm.options` (or, in my case, `-Duser.language=en-US` as a property in pom.xml). Unfortunately, `-Dfile.encoding=utf-8` doesn't work. Using PowerShell is not an option for me (I love bash, no way I'll switch to inferior PS). And changing the terminal encoding to ISO-8859-1 feels like a downgrade. I really like liberty to go UTF-8, as did the rest of the world some 20 years ago. – rslemos Apr 23 '21 at 23:59
  • Are you using a terminal with an option like this? (Does setting the character set this way help? ) https://i.stack.imgur.com/G51mw.png – Scott Kurz Apr 24 '21 at 01:01
  • The problem is not on the terminal. It renders utf-8 perfectly. The problem is OpenLiberty, which outputs iso-8859-1. – rslemos Apr 24 '21 at 01:19
  • I updated my answer. Since your original question said you might just want to run in English I answered that part but was a bit incomplete with the rest of my answer. Maybe this is what you are looking for. – Scott Kurz Apr 24 '21 at 12:48
  • `-Dfile.encoding=utf-8` in `jvm.options` is being ignored, I don't know why yet. Maybe the real culprit is either `liberty-maven-plugin` or `liberty-arquillian-managed`. I'm still investigating my setup. – rslemos Apr 24 '21 at 14:22
  • If you try to mix a jvm.options file `src/main/liberty/config/jvm.options` with the liberty-maven-plugin-generated one from e.g. `-Dfile.encoding=utf-8` you'll find that your source jvm.options just gets overwritten in target. There is no merging performed, so you'd need to specify all JVM options as liberty.jvm.* props. Wondering if this could be your problem? – Scott Kurz Apr 24 '21 at 16:08
  • Actually I don't have a `jvm.options`. I'm only using maven properties. – rslemos Apr 24 '21 at 18:58
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/231554/discussion-between-scott-kurz-and-rslemos). – Scott Kurz Apr 24 '21 at 21:31