How to change the encoding of wsimport-generated files?
Asked Answered
I

5

8

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?

Improvvisatore answered 10/12, 2009 at 14:57 Comment(2)
why exactly do you want not to use UTF-8?Stochmal
Because on this project all other java surces are Cp1252 encoded. Mixed source encodings can cause the compiler trouble, especially when using non ASCII characters. So I want the wsimport to generate java sources that are Cp1252 encoded.Improvvisatore
I
3

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.

Ineluctable answered 15/12, 2009 at 14:42 Comment(0)
G
4

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...

Gasteropod answered 16/3, 2018 at 17:54 Comment(0)
I
3

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.

Ineluctable answered 15/12, 2009 at 14:42 Comment(0)
Q
3

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).

Quadrennial answered 15/1, 2019 at 11:58 Comment(2)
It works perfect +1. For me it also works on previous version (2.2.7)Geomorphology
Worked for me too! +1Imray
G
2

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!
    )
}
Geomorphology answered 11/12, 2019 at 11:37 Comment(0)
S
0

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...
Spot answered 16/3, 2018 at 17:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.