9
votes

I generate server/client from my wsdl/xsd's using the cxf-codegen-plugin for Maven. All the types created have default no-arg-constructors, which makes them a pain to work with.

Is there any way to make Apache CXF generate a full constructor aswell, with all the members of the class as arguments?

1
I'm facing the same problem. If you have found a solution please comment.heldt

1 Answers

7
votes

This plugin is just a fancy wrapper around xjc.

There are two xjc plugins that address your problem space:

  • Value-constructor exactly what you are looking for.
  • Fluent-api not exactly what you are looking for, but many prefer a fluent api to value constructors.

You need to add the required dependencies and then configure the plugin to enable those plugins in xjc, e.g.

<plugin>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-codegen-plugin</artifactId>
  <configuration>
    <defaultOptions>
      <extraargs>
        <extraarg>-xjc-Xvalue-constructor</extraarg>
      </extraargs>
    </defaultOptions>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-value-constructor</artifactId>
      <version>3.0</version>
    </dependency>
    <dependency>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-basics</artifactId>
      <version>0.6.4</version>
    </dependency>
  </dependencies>
</plugin>

Note: the above makes this a default for all executions, if you want to enable those options for a specific execution only, then just add the <configuration> bit into that specific execution.