8
votes

Is there a way in CXF to generate JAXB classes with full constructors (i.e., with the members of the class as arguments)?

1

1 Answers

12
votes

Use the value-constructor xjc plugin.

Maven snippet:

        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>${cxf.version}</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <defaultOptions>
                            <extraargs>
                                <extraarg>-xjc-Xvalue-constructor</extraarg>
                            </extraargs>
                        </defaultOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
            <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.2</version>
                </dependency>
            </dependencies>
        </plugin>