How to change comments language of generated code from wsimport.exe

Viewed 1755

I want to import a .wsdl-file using %JAVA_HOME%/bin/wsimport.exe into my Java project. Everything works fine, except that the language of the comments is in german, but I want it to be in english. How can I change the language used by wsimport.exe?

4 Answers

No, the author of the question is not mistaken. It seems as wsimport takes the language from the operating system. In our project we had machines with German and English language settings. The code was generated accordingly:

English machine:

/**
 * <p>Java class for abstractRequest complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.

German machine:

/**
 * <p>Java-Klasse für abstractRequest complex type.
 * 
  * <p>Das folgende Schemafragment gibt den erwarteten Content an, der in dieser Klasse enthalten ist.

As mentioned in the answer to this question How to change javadoc comments language when generate java from wsdl with CXF wsdl2java? the language can be set in the command line like

-Duser.language=en

For Oracle JDK 8, it is possible to call the WsImport class directly, and configure the language of the generated comments by setting the Locale to your desired language (the web service tools have been removed in Java 11).

Locale.setDefault(new Locale("en"));
List<String> args = new Arraylist<>();
// add other options
args.add(wsdlFile.getAbsolutePath());
com.sun.tools.internal.ws.WsImport.doMain(args.toArray(new String[0]));

And another alternative using Apache CXF, which is hopefully more future proof:

Locale.setDefault(new Locale("en"));
// options: https://cxf.apache.org/docs/wsdl-to-java.html
List<String> args = new ArrayList<>();
args.add("-suppress-generated-date");
args.add("-d");
args.add(new File("src/main/java").getAbsolutePath());
args.add("-p");
args.add("com.company.targetpackage");
args.add(new File("sample.wsdl").getAbsolutePath());

WSDLToJava wsdlToJava = new WSDLToJava();
wsdlToJava.setArguments(args.toArray(new String[0]));
wsdlToJava.run(new ToolContext());

Using the following maven dependencies:

<dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-codegen-plugin</artifactId>
  <version>3.3.2</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
  <version>2.3.2</version>
</dependency>
Related