Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change java.locale.providers via System.setProperty has no effect

To change the locale providers in java 9+( I am using 21 right now) I can start java with -Djava.locale.providers=COMPAT,SPI

How ever I tried to set this property programmatically via
System.setProperty("java.locale.providers", "COMPAT,SPI");

But this not take effects.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The project is a web based application and I add above code in ServletContextListener#contextInitialized method

@WebListener
public class StartUp implements ServletContextListener {

@Override
public void contextInitialized(ServletContextEvent event) {
    System.setProperty("java.locale.providers", "COMPAT,SPI"); 
 }

>Solution :

Refer to the documentation for class LocaleServiceProvider:

The search order of locale sensitive services can be configured by using the java.locale.providers system property. This system property declares the user’s preferred order for looking up the locale sensitive services separated by a comma. As this property value is read and cached only at the initialization of this class, users should specify the property on the java launcher command line. Setting it at runtime with System.setProperty(String, String) is discouraged and it may not affect the order.

I believe that your servlet container should provide the capability to configure such [system] properties. Since I did not find any details about which servlet container you are using, I cannot help you further. I suggest you refer to that servlet container’s documentation.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading