Java Gradle Eclipse - UTF-8 Symbols Showing Before Build In IDE But Not After Build
i'm fairly new to coding and currently im trying to build my first fat JAR with gradle in eclipse. My project generates a HTML file with data i get from a JSON file. some of the strings in there use UTF-8 symbols/emojis. I managed to get them into my java objects with "Jackson" and by using the getBytes() method for the strings. When i generate the HTML from those objects in eclipse they show up the right way (when opened in browser outside of eclipse). The problem occurs, when i build the fat jar with "gradlew jar" (i had to make some changes in build.gradle to jar to make it contain the dependencies). Everything works fine, besides the UTF-8 symbols not showing, instead i get a "?", like the encoding is not set right. So i think the problem is encoding settings in gradle.
What i tried so far is adding this to gradlew.bat:
set GRADLE_OPTS=-Dfile.encoding=utf-8
this to build.gradle :
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
and this to gradle.Properties
systemProp.file.encoding=utf-8
like mentioned in this thread Show UTF-8 text properly in Gradle
None of those seem to help. Any ideas? Im stuck, struggle to find a solution.
Answer
-Dfile.encoding=UTF-8
sets the default encoding used at runtime when running your compiled code, e.g. java -Dfile.encoding=UTF-8 -jar ...
. Don't mix it up with the encoding that is used by the Java compiler to read the .java
files: javac -encoding ...
.
To avoid to set it on the command line, you can set it also programmatically via System.setProperty("file.encoding", "UTF-8");
. But better set the encoding where it used, e.g. instead of BufferedWriter writer= Files.newBufferedWriter(path);
use BufferedWriter writer= Files.newBufferedWriter(path, StandardCharsets.UTF_8);
.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM