5

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?

sfandler
  • 610
  • 5
  • 23

4 Answers4

5

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
stefitz
  • 446
  • 6
  • 10
  • 2
    the command doesn't accept -Duser.language=en parameter and shows the help page everytime – hoomb Mar 19 '19 at 08:30
  • @nicmon: Not sure, what you executed (or what you mean by "the command"). But if you tried `wsdl2java -Duser.language=en` then yes, this would not work. As far as I remember, you have to edit the wsdl2java script (wsdl2java.bat or wsdl2java bash script) and change a line in the script to something like `"%JAVA_HOME%\bin\java" -Xmx%JAVA_MAX_MEM% -Duser.language=en ...` – stefitz Mar 28 '19 at 19:21
  • 3
    Thanks to https://stackoverflow.com/a/56655305/1004651 I managed to make wsimport follow this approach by setting the environment variable JAVA_TOOL_OPTIONS to `-Duser.language=en`. – Matthias May 06 '20 at 20:13
1

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]));
Reto Höhener
  • 5,419
  • 4
  • 39
  • 79
0

I think you are mistaken here. Javadoc content is nothing but a compilation of information found in Java source code.

When your Javadoc HTML contains up German content - then because people have written German text into the java source code. You can't just change the import process - you have to find somebody who translates the German text to English!

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • 1
    What I mean are the comments of the class, of the getters and setters, which are generated from wsimport.exe. So the comments are also generated from wsimport.exe. It has to be possible somehow to change that language. – sfandler Sep 15 '17 at 09:11
  • Maybe you could add some example content to your question. I am not getting your problem. – GhostCat Sep 15 '17 at 09:12
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>
Reto Höhener
  • 5,419
  • 4
  • 39
  • 79