Pages

Wednesday, June 15, 2016

support for special charecter while compile in eclipse unmappable character for encoding UTF-8

I faced problem while compiling xsd to java using apache xmlbeans maven plugin that
generated code was not matched same as in xsd, given xsd file has special German character in element as


 <xs:enumeration value="in Ablöse"/> 
and when it gets converted to java expected as

static final Enum IN_ABLÖSE = Enum.forString("inAblöse");



my maven plugin was failed to write proper special character in generated java code. though in eclipse editor

i able to see proper character for xsd file but generated java was not. After research i found that its affected by eclipse IDE and the maven pom file that you specify, I tried to google and found that you can provide encoding type to maven pom as below


       

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <UTF-8</encoding>
    </configuration>
</plugin>
 
 


I also noticed that this is not sufficient many maven plugins will by default use the "project.build.sourceEncoding" property and this applies to all plugin mentioned to your pom file.

I did following

1 First i opened xsd files in textpad and changed the file format to 'PC' and encoding to 'UTF-8'.

2 Next in my eclipse preferences kept xsd file encoding type as UTF-8 this can be done as  windows>preferences>General>Content Types>Text>xml>xsd check down default encoding to UTF-8.

3 Right click project>properties>Resources>Text file encoding>set to inherited from container (Cp1252).

4 In pom file remove "project.build.sourceEncoding" property so that compile will take default of container/eclipse editor properties


and this worked.