Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can ApacheCXF generate full constructors when using the cxf-codegen-plugin for Maven?

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?

like image 332
david1563 Avatar asked Mar 30 '11 14:03

david1563


1 Answers

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.

like image 84
Stephen Connolly Avatar answered Oct 06 '22 03:10

Stephen Connolly