cxf-codegen-plugin doesn't generate UTF-8-compatible files

4.2k views Asked by At

I have this POM below which doesn't generate the files in UTF-8.

The WSDL files contain XSD files which in turn use French accentuated characters like é, è, à, etc. I have no hand on the WSDL as I have to use those as they are delivered.

The WSDL and XSD files are correctly encoded in UTF-8 without BOM, according to Notepad++.

When I try to generate the java files, those java files are generated in the DOS/Windows charset, again according to Notepad++.

I want that the java files are generated in UTF-8 because all our projects use UTF-8 and the java classes can't be compiled locally by our developpers on Windows because of the following error: error: unmappable character for encoding UTF-8.

I read the documentation of CXF about this and made everything like described, including adding the two dependencies of JAXB directly in the plugin. Yet it doesn't work.

I'm using CXF version 2.6.10 (released after 2.6.1 which included the option to generate files in a specific encoding).

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>

                <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${basedir}/src/main/webapp/WEB-INF/wsdl/service_v1.wsdl</wsdl>
                        <bindingFiles>
                            <bindingFile>${basedir}/src/main/xjb/bindings.xml</bindingFile>
                        </bindingFiles>                                         
                    </wsdlOption>
                    <wsdlOption>
                        <wsdl>${basedir}/src/main/webapp/WEB-INF/wsdl/service_internals_v1.wsdl</wsdl>
                        <bindingFiles>
                            <bindingFile>${basedir}/src/main/xjb/internals-bindings.xml</bindingFile>
                        </bindingFiles>                                                                                                                                                                             
                    </wsdlOption>                                                                                                                 
                </wsdlOptions>
                <extraargs>
                    <extraarg>-validate</extraarg>
                    <extraarg>-verbose</extraarg>
                    <extraarg>-p</extraarg>
                    <extraarg>be.mycompany</extraarg>
                    <extraarg>-exceptionSuper java.lang.Exception</extraarg>
                </extraargs>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-xjc</artifactId>
            <version>2.2</version>
        </dependency>
    </dependencies>
</plugin>
1

There are 1 answers

0
Olivier Grégoire On BEST ANSWER

I read the documentation in the link mentioned above. It says to use jaxb 2.2. I now checked the Jira issue and read that I have to use the version 2.2.5 instead of the version 2.2.

So my POM has this instead of what's written in the question:

    <dependencies>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.5</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-xjc</artifactId>
            <version>2.2.5</version>
        </dependency>
    </dependencies>

Finally, I tried to use the latest version of JAXB, 2.2.11, but this one introduced new compilation issues so I kept the 2.2.5 in the end.