How to generate ToString() with cxf-codegen-plugin ?

Solution Verified - Updated -

Environment

  • Red Hat JBoss Fuse
    • 6.x
  • Apache CXF

Issue

  • We are using cxf-codegen-plugin version 3.0.4.redhat-620133 . We want to generate toString methods from wsdl, so I add the -xjc-Xts argument and the dependency:

       ~~~
    


    org.apache.cxf.xjcplugins
    cxf-xjc-ts
    ${cxf-xjc-utils-version}

    <cxf-xjc-utils-version>3.0.2</cxf-xjc-utils-version>
    

- It fails with compilation errors:

java.lang.ClassNotFoundException: org.apache.cxf.xjc.runtime.JAXBToStringStyle

The generated classes use `org.apache.cxf.xjc.runtime.JAXBToStringStyle` to create the toString methods . 

- It seems we need to use, 


org.apache.cxf.xjc-utils
cxf-xjc-runtime

~~~

  • Which version should I use for cxf-xjc-runtime?
    Or, is there a way to generate toString() code that does not use cxf-xjc-runtime dependency?

Resolution

  • In the pom.xml, file, you will need the following dependencies,

       ~~~
    



    org.apache.cxf.xjc-utils
    cxf-xjc-runtime
    3.0.2


    commons-lang
    commons-lang
    2.6.0.redhat-4

                   <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.5.3</version>
            <extensions>true</extensions>
        </plugin>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>3.0.4.redhat-620133</version>
            <executions>
                <execution>
                    <phase>
                    generate-sources
                </phase>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                    <configuration>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>${basedir}/src/main/resources/wsdl/greeter.wsdl</wsdl>
                                <extraargs>
                                    <extraarg>-xjc-Xts</extraarg>
                                </extraargs>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.apache.cxf.xjcplugins</groupId>
                    <artifactId>cxf-xjc-ts</artifactId>
                    <version>3.0.4</version>
                </dependency>
          </dependencies>
    </plugin>
    

    ~~~

The above configuration works.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments