I recently had to solve the problem with JAXB to generate bad source from XSD. The problem was basically that the XSD source from which they were subsequently generated Java code contained in the tag
What hapened when I then started building my code with Maven, I obviously – I had got exception that the generated files contain non-UTF characters. So I started investigation how to force the JAXB to generate source code in UTF-8 instead of using platform specific encoding.
A quick look into the source code JAXB again assured me that JAXB is not (politely spoken) the best written piece of software because there is something like this:
private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
This piece of code always returns encoder by platform depend encoding and there is no way, how to force different encoding and only one way is to tell JVM wat encoding is the right one.
Fortunately, the solution is easy. Just set the system variable MAVEN_OPTS like this:
export MAVEN_OPTS="$MAVEN_OPTS -Dfile.encoding=UTF-8"
What surprised me that this issue is not documented, and even Google could not help me. So I hope these few lines will help to someone.