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

前端 未结 7 1729
逝去的感伤
逝去的感伤 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:59

    My answer is for those who can't afford any third part dependency on their generated code.

    The org.jvnet.jaxb2_commons:jaxb2-basics plugin adds a lots of org.jvnet includes in the generated code and your project will depend on org.jvnet.jaxb2_commons:jaxb2-basics-runtime.

    The org.andromda.thirdparty.jaxb2_commons:commons-lang-plugin plugin generates code which depends on commons-lang:commons-lang. This dependency might be easier to bear depending on the situation.

    I finally found this source code, it might be included in com.sun.xml.bind:jaxb-xjc at some point (version 2.2.4 ?), but until then I can't see any other solution than writing your own plugin.

    PS: I can't access confluence.highsource.org, I get a 404. I guess it might have been helpful.

    PPS: In my situation, the application I am building is targeted to an environment which has a very limited set of allowed Java libraries (incongruous security restrictions). I was a bit disappointed by the fact that jaxb2_commons includes a bunch of org.jvnet dependencies in the generated source, just for adding a boring equals method. I can understand the strategy of jvnet, their tools are very powerful, I may just be trying and using a sledgehammer to crack a nut. Still, I was sorry to note that it was so difficult to find a suitable tool for my situation.

提交回复
热议问题