0

I want my Spring Boot application to use default charset CP866. So, during Tomcat startup, I added the following in Environment variable:

JAVA_TOOL_OPTIONS=-Dfile.encoding=CP866

Still, it seems the change is not in effect, the application is not using CP866 as the default charset. Also, when I see Java properties using java -XshowSettings, it still shows: file.encoding = UTF-8

Please share if you have any idea how to achieve the change?

Note: after migrating from a new server, in my app, an image/photo update feature is not working properly. I sense this is because of encoding issue on the new system. In the previous server, the file.encoding was CP866. I don't prefer any code change for the new server.

Thanks in advance.

Md.
  • 496
  • 4
  • 11
  • Are you using Spring Boot embedded or standalone Tomcat server? How do you deploy/start your application? This also could be useful for you: https://stackoverflow.com/questions/3933300/difference-between-java-opts-and-java-tool-options – Ilya Lapitan Dec 14 '19 at 04:13
  • I am using Tomcat. I deploy my application as an WAR file using Tomcat manager. I tried both JAVA_OPTS and JAVA_TOOL_OPTIONS in Tomcat startup script. However, nothing helped. – Md. Dec 14 '19 at 04:49
  • Can you please check this: 1. stop Tomcat 2. define the environment variable in the console: `export JAVA_OPTS=-Dfile.encoding=CP866` 3. start Tomcat 4. verify that encoding configuration is applied during Tomcat startup `ps -ef | grep tomcat | grep file.encoding` There should be output something like that: /usr/local/java/bin/java .. **-Dfile.encoding=CP866** ... -Djava.io.tmpdir=/home/ilya/Downloads/apache-tomcat-8.5.50/temp org.apache.catalina.startup.Bootstrap start If you see -Dfile.encoding=CP866 in your output now you can deploy your application. – Ilya Lapitan Dec 14 '19 at 06:12
  • Exactly how @IlyaLapitan writes - you do need to use `JAVA_OPTS`. And it would help if you share how exactly you startup your Tomcat (via `tomcat/bin/startup.sh`? not from an IDE?) and your configuration script where you put the `JAVA_OPTS=...` line(s). – Petr Bodnár Dec 14 '19 at 10:31

0 Answers0