What to do when an UnsupportedCharsetException occurs in a lightweight JRE

Overview

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.

Why the exception occurs

This is because extended character codes such as ʻEUC-JPare not included in thejava.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")

approach

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

What to do when an UnsupportedCharsetException occurs in a lightweight JRE
What to do when a javax.el.PropertyNotWritableException occurs
What to do when IllegalStateException occurs in PlayFramework
What to do and how to install when an error occurs in DXRuby 1.4.7
Notes on what to do when a WebView ClassNotFoundException occurs in JavaFX 12
What to do when a null byte error occurs
What to do when javax.batch.operations.JobStartException occurs
What to do if an error occurs when nokogiri enters when bundle install
What to do if an error occurs when doing npm install axios in React + Typescript project
What to do if ClassNotFoundException occurs when starting Tomcat
What to do when rails creates a 〇〇 2.rb file
What to do if an ActionController :: UnknownFormat error occurs
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
What to do if ffi installation fails when launching an application in Rails
What to do if an error occurs in VS Code when importing a django module or your own module installed by pip install
What to do if you get a java.io.IOException in GlassFish
What to do when Method not found in f: ajax
What to do when you launch an application with rails
What to do when Cannot format given Object as a Date in convertDateTime of JSF
What to do when a could not find driver appears when connecting to a DB in a Docker environment
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
[Rails 6] What to do when a missing a template error occurs after introducing haml [Super easy]
What to do if you get a gcc error in Docker
Collecting client information when an error occurs in a web application
What to do when the changes in the Servlet are not reflected
What to do if you get a DISPLAY error in gym.render ()
What to do when you become a Problem During Content Assist
What to do when you run into a docker-compose node_modules problem
What to do when an error occurs in rails db: migrate ((StandardError: An error has occurred, this and all later migrations canceled :))
[Programming beginner] What to do when rails s becomes an error in the local development environment
What to do if you get a JNI shared library error when trying to build in Eclipse
A reminder when an aapt.exe error occurs
What to do when undefined method ʻuser_signed_in?'
What to do if you get a groovy warning in Thymeleaf Layout
What to do when Blocked Host: "host name" appears in Ruby on Rails
no space left on device What to do if an error occurs
What to do if tomcat process remains when tomcat is stopped in eclipse
What to do if you get an error when you hit Heroku logs
What to do when "call'Hoge.connection' to establish a connection" appears on rails c
What to do if zip dies if there is a pom when making an executable jar with gradle
What to do if Operation not permitted is displayed when you execute a command in the terminal
How to make a lightweight JRE for distribution
What to do when debugging "Source not found"
What do you use when converting to String?
What to do when you want to delete a migration file that is "NO FILE"
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
<f: ajax> Unable to attach <f: ajax> to non-ClientBehaviorHolder What to do when you become a parent
What to do when the value becomes null in the second getSubmittedValue () in JSF Validator
What to do when rails db: seed does not reflect in the database
wildflly10 java8 ERROR [org.jboss.jca.core.tx.jbossts.XAResourceRecoveryImpl] (Periodic Recovery) IJ000906 What to do if an error occurs
Androd: What to do about "The Realm is already in a write transaction in"
What to do when is invalid because it does not start with a'-'
When using a list in Java, java.awt.List comes out and an error occurs
[Ubuntu] What to do when MongoDB cannot be started due to a SocketException error
What you need to know before writing a test in an iOS app
What to do if you get an "A server is already running." Error when you try to start the rails server
What to do if Command line is too long appears when building a gradle project in Intellij IDEA
[React.useRef] What to do when the latest state cannot be referenced in the event listener
After installing'devise''bootstrap' of gemfile with rails, what to do when url is an error
What to do if you get a wrong number of arguments error in binding.pry