2
votes

I'm using the cxf-codegen-plugin to generate Java classes from wsdl files. I want to add annotations to once of the classes and I specify a Binding File and use the jaxb2-basics-annotate plugin to do so. The generated files don't contain the the annotation specified in the binding file.

Here is the configuration in the pom file

<plugins>
    <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>2.7.4</version>
        <executions>
            <execution>
                <id>generate-sources</id>
                <phase>generate-sources</phase>
                <configuration>
                       <wsdlOptions>
                           <wsdlOption>
                               <wsdl>src/main/resources/wsdl/QueryJobService.wsdl</wsdl>
                               <wsdlLocation>classpath:wsdl/QueryJobService.wsdl</wsdlLocation>
                               <extraargs>
                                   <extraarg>-xjc-Xannotate</extraarg>
                               </extraargs>
                               <bindingFiles>
                                   <bindingFile>src/main/resources/wsdl/xsd/job-bindings.xjb</bindingFile>
                               </bindingFiles>    
                           </wsdlOption>
                       </wsdlOptions>
                   </configuration>
                   <goals>
                       <goal>wsdl2java</goal>
                   </goals>
               </execution>
           </executions>
           <dependencies>
               <dependency>
                   <groupId>org.jvnet.jaxb2_commons</groupId>
                   <artifactId>jaxb2-basics-annotate</artifactId>
                   <version>1.0.1</version>
               </dependency>
           </dependencies>
       </plugin>
   </plugins>

and here is the binding file

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:annox="http://annox.dev.java.net"
    xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
    version="2.1">

<jaxb:bindings schemaLocation="data.xsd" node="/xs:schema">
    <jaxb:bindings node="//xs:complexType[@name='resource']">
    <annox:annotate target="class">
            <annox:annotate annox:class="javax.xml.bind.annotation.XmlSeeAlso" value="model.common.sm.dcp.com.data._1.SimOrder"/>
        </annox:annotate>
    </jaxb:bindings>
</jaxb:bindings>

running maven in debug mode doesn't show anything strange. Is it so that cxf-codegen-plugin and jaxb2-basics-annotate don't work together ? Or is there something wrong with my configurations ?

1

1 Answers

2
votes

It should work with CXF.

Please make sure that bindings are applied at all. Try to replace annox:annotate with something like <jaxb:class name="FooBar"/> - does it get generated as FooBar?

Also try the new Java Syntax: https://github.com/highsource/jaxb2-annotate-plugin instead of XML.

Finally, I guess you might be missing this attribute on your root jaxb:bindings element:

jaxb:extensionBindingPrefixes="annox"

See this example.

If nothing helps, send me a PR on github.

SO disclaimer: I'm the author of jaxb2-annotate-plugin.