externally create jaxb annotations for class

后端 未结 2 1699
醉酒成梦
醉酒成梦 2021-02-10 00:58

So, usually I apply JAXB annotations in the code as follows:

package com.example;

@XmlRootElement(name = \"Foo\", namespace = \"example.com\")
@XmlType(name = \         


        
2条回答
  •  旧时难觅i
    2021-02-10 01:58

    If you just need to add @XmlType(name = "Foo", namespace = "example.com") annotation to the generated class you can use JAXB Annotate Plugin. Here is documentation about how to define annotations in external binding files.

    If you're using CXF and maven you can also you cxf-codegen-plugin somehow like this

    
        org.apache.cxf
        cxf-codegen-plugin
        ${cxf.version}
        
            
                generate-sources
                generate-sources
                
                    wsdl2java
                
                
                    ${service.src.dir}
                    
                        
                            service.wsdl
                            
                                -xjc-Xannotate
                                -b
                                ${wsdl.dir}/bindings.xjb
                            
                        
                    
                
            
        
        
            
                org.jvnet.jaxb2_commons
                jaxb2-basics-annotate
                ${jaxb.commons.version}
            
                        
    
    

    You can also use maven-jaxb2-plugin:

    
    org.jvnet.jaxb2.maven2
    maven-jaxb2-plugin
    ${maven-jaxb2.version}
    
        
            process-xsd
            
                generate
            
            generate-sources
            
                
                    **/*.xsd
                
                
                    **/*.xjb
                
                ${jaxb.src.dir}
                true
                
                    -Xannotate
                
                
                    
                        org.jvnet.jaxb2_commons
                        jaxb2-basics-annotate
                        ${jaxb.commons.version}
                    
                
            
        
    
    
    

    Here is sample binding file:

    
    
        
            
                
                    
                
            
        
    
    
    

    If you need to modify @XmlRootElement too, just add another one annox:annotate element:

    
    

提交回复
热议问题