How to change the encoding of wsimport-generated files?
Question
I am using the wsimport ant task of JAX-WS to generate sources based on some wsdl.
However, these generated sources all seem to be UTF-8 encoded. Is there a way to change the encoding of the files wsimport task produces?
Solution
This is somewhat badly documented. WSImport uses XJC (from JAXB) to create Java files and the documentation here indicates that changing the character encoding in the XML file should suffice (although I have not tried this). If you are content with running JAXB by hand then you can also configure this via the JAXB_ENCODING property on your JAXBContext.
OTHER TIPS
I post with my register account:
Set the environment variable JAVA_TOOL_OPTIONS
to -Dfile.encoding=UTF8
Example in windows:
set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
c:>wsimport -keep ... file.wsdl
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 parsing WSDL...
Generating code...
Set the environment variable to JAVA_TOOL_OPTIONS
to -Dfile.encoding=UTF8
Example from terminal in windows:
set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
c:>wsimport -keep ... file.wsdl
Picked up `JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8`
parsing WSDL...
Generating code...
wsimport 2.2.9 in JDK 8 has the -encoding
option that can be used for this. For example:
wsimport -keep -s c:\path\to\src c:\wsdl\myService.wsdl -encoding cp1252
I can't find this option in either wsimport 2.1.6 (JDK 6) or 2.2.4-b01 (JDK 7).