Search code examples
javajaxbcxfwsdl2java

Annotating CXF (wsdl2java) generated package


I need to add package level annotation (XmlJavaTypeAdapters type adapter). The problem is that when I run wsdl2java it generates package-info.java file for that package.

When I try to add my own package-info.java I get error: "the type package-ingo is already defined".

Is there a way to inject my annotation to package-info.java?? Maybe any other ideas?

thanks


Solution

  • After some research I used external mapping file. For all that have similar problem to mine I have described below what I have found.

    If you are using "cxf-codegen-plugin" for generating source code from WSDL you can't use solution with package-info.java. This is because generated code propably will already contain this file. You cannot also add annotation to your class because it is generated. The only solution is to provide your own mapper.

    First of all you have to write custom mapper. After that you should define xjb mapping file and finally add additional configuration to your pom.xml. You can read about first two steps here.

    To add external mapping file to cxf-codegen-plugin you have to add something like this to configuration node in plugin definition:

    <defaultOptions>
        <bindingFiles>
            <bindingFile>${basedir}/src/main/resources/mapping.xjb</bindingFile>
        </bindingFiles>
        <noAddressBinding>true</noAddressBinding>
    </defaultOptions>
    

    Note that you should not pass extra parameters to xjc as described here because it will not work.

    Hope this will help anybody :)