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?
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?
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.
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...
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.
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).
If you're using wsimport through ant task using gradle
, you can simply use encoding
property specifying the desired encoding in wsimport
. I tested with wsimport version 2.2.7
configurations {
schemaGenerationBeans
}
dependencies {
// dependencies per compilar schemas
schemaGenerationBeans 'com.sun.xml.bind:jaxb-xjc:2.2.7'
schemaGenerationBeans 'com.sun.xml.ws:jaxws-ri:2.2.7'
schemaGenerationBeans 'com.sun.xml.ws:jaxws-tools:2.2.7'
}
task generateJaxb {
ant.taskdef(name: 'wsimport', classname: 'com.sun.tools.ws.ant.WsImport', classpath: configurations.schemaGenerationBeans.asPath)
ant.wsimport(wsdl: "$projectDir/src/main/resources/somepath/YOUR_WSDL.wsdl",
wsdlLocation: "/somepath/YOUR_WSDL.wsdl", // relative path for generated classes
package: 'org.your.package.xsd',
xnocompile: 'true',
xendorsed: 'true',
sourcedestdir: "$projectDir/src/main/java/",
encoding : 'utf-8' // DESIRED ENCODING PROPERTY!
)
}
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...
© 2022 - 2024 — McMap. All rights reserved.