Generating hashCode() and equals() when creating Java classes using Mojo Jaxb2 maven plugin

前端 未结 7 1728
逝去的感伤
逝去的感伤 2020-12-03 15:18

The code I\'m working on is using jaxb2-maven-plugin from org.codehaus.mojo to generate Java classes from XSD schema. I\'m looking for a way to aut

7条回答
  •  一整个雨季
    2020-12-03 15:46

    For me the simplest way to do is using maven-jaxb2-plugin (as mentioned in the accepted answer):

    1. Add in pom.xml
     
        org.jvnet.jaxb2_commons
        jaxb2-basics
        0.11.1
    
    
    1. Add the plugin
    
        org.jvnet.jaxb2.maven2
        maven-jaxb2-plugin
        0.14.0
        
            
                
                    generate
                
                
                    src/main/resources
                    target/generated-sources
                    my.package
                
            
        
        
            true
            
                -XtoString
                -Xequals
                -XhashCode
            
            
                
                    org.jvnet.jaxb2_commons
                    jaxb2-basics
                    0.11.1
                
            
        
    
    

    See

    • JAXB2 Basics Plugins maven-jaxb2-plugin documentation/example
    • Add toString, hashCode, equals while generating JAXB classes in Java - Another similar stackoverflow thread

提交回复
热议问题