As introduced in the article How to make a lightweight JRE for distribution, in Java 9 or later, create a lightweight JRE consisting of the minimum required modules. can do.
You can use the jdeps
command that comes with the JDK to find out which modules should be included in the lightweight JRE, but when you run your app on the lightweight JRE you created, you may encounter the following exceptions:
UnsupportedCharsetException: EUC-JP
This is an exception that occurs when you specify an unsupported character code. It is an exception that is not raised in a normal JDK that is not a lightweight JRE, but it should contain the minimum required modules indicated by the jdeps
command, but it has raised an exception.
This means that the jdeps
command alone does not have enough modules to include in the lightweight JRE.
This article will show you how to avoid the above exceptions when using lightweight JREs.
This is because extended character codes such as ʻEUC-JPare not included in the
java.base` module.
By the way, in the Javadoc of the jdk.charsets
module of JDK9, the following description there is.
Provides charsets that are not in java.base (mainly double-byte characters and IBM character sets).
This means that Japanese character code sets require an additional jdk.charsets
module.
If you specify the character code using the Charset.forName
method etc. in the Java source code as shown below, the jdeps
command does not display the jdk.charsets
module, so create a lightweight JRE. You need to be careful when doing so.
Charset.forName("EUC-JP")
When creating a lightweight JRE with the jlink
command, you can handle extended character codes by including the jdk.charsets
module.
jlink --compress=2 --module-path ../jmods --add-modules java.base,jdk.charsets --output jre
Recommended Posts