1

Having a computer with the system property user.language set to de, I would like to see the compiler messages in English. In this post two methods are proposed for java8:

  1. to use the -Duser.language=en switch on the command line, but -D isn't shown in the list of available switches for javac 20 any more.

  2. to set an environment variable by the name JAVA_TOOL_OPTIONS under Windows. This, however, sets both java and javac to the desired language, but I would like only the compiler language to be changed.

Edit

The above mentioned post also tells trying -J-Duser.language=en which is rejected at my site with Fehler: Ungültiges Kennzeichen: .language=en which might read in English "Error: Invalid token/indicator: .language=en"

Edit 2

I accepted DuncG's answer, but the actual solution is in his comment to the original question. Thank you.

Jörg
  • 214
  • 1
  • 9
  • That error looks like somehow it has read whitespace after `user` and before `.language=en` - perhaps try `javac '-J-Duser.language=en' xyz.java` (double quoted in Windows, single in GNU/Linux). – DuncG Mar 27 '23 at 16:24
  • Both with double quotes and single quote it works on windows. Thank you. – Jörg Mar 27 '23 at 17:27

1 Answers1

1

On my JDK installation the -J flag can be used, though this does not work for all language codes:

C:\dev>javac -J-Duser.language=de ayx.java
Fehler: Datei nicht gefunden: ayx.java
Verwendung: javac <Optionen> <Quelldateien>
Mit --help können Sie eine Liste der möglichen Optionen aufrufen

C:\dev>javac -J-Duser.language=en ayx.java
error: file not found: ayx.java
Usage: javac <options> <source files>
use --help for a list of possible options

EDIT

The above works on Linux or Windows CMD, but Windows Powershell reports an error as appears to process the single parameter -J-Duser.language=de as two parameters -J-Duser then .language=de. For Powershell just add quotes to handle as single parameter value:

PS C:\dev> javac -J-Duser.language=de xyz.java
error: invalid flag: .language=de
Usage: javac <options> <source files>
use --help for a list of possible options

PS C:\dev> javac "-J-Duser.language=de" xyz.java
Fehler: Datei nicht gefunden: xyz.java
Verwendung: javac <Optionen> <Quelldateien>
Mit --help können Sie eine Liste der möglichen Optionen aufrufen
DuncG
  • 12,137
  • 2
  • 21
  • 33
  • Thanks for your response. I should have mentioned this possibility, too, and edited my post. Unfortunately it doesn't work for me. – Jörg Mar 27 '23 at 15:17
  • Maybe have a look at the JDK20 module `jdk.compiler` in good IDE or src.zip. For my OpenJDK20 there are language packs for `zh`, `ja`, `de` in package `com.sun.tools.javac.resource` and other `*.resource` folders and `en` is the default inside `javac.java` – DuncG Mar 27 '23 at 16:05