使用 Mojo Jaxb2 maven 插件创建 Java 类时生成 hashCode() 和 equals() [英] Generating hashCode() and equals() when creating Java classes using Mojo Jaxb2 maven plugin
问题描述
我正在处理的代码使用来自 org.codehaus.mojo
的 jaxb2-maven-plugin
从 XSD 模式生成 Java 类.我正在寻找一种方法来为这些类自动实现 equals()
和 hashCode()
方法,但似乎没有办法.我知道还有其他 JAXB2 Maven 插件可以做到这一点(例如 http://confluence.highsource.org/display/J2B/Home),但我想知道你们中是否有人以前遇到过这个问题,是否有办法解决这个问题修复它.我正在使用 xjc
目标生成类.
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 automatically implement equals()
and hashCode()
methods for those classes, but it seems there is not a way. I know that there are other JAXB2 Maven plugins that do that (http://confluence.highsource.org/display/J2B/Home for example), but I was wondering if anyone of you encountered this issue before and if there's a way for fixing it. I'm generating the classes using the xjc
goal.
推荐答案
您提到的 JAXB2 Basics 不是 maven-jaxb2-plugin
的属性,它是 JAXB 2 的独立集.x 插件,您可以与 XJC 一起使用 - 或 jaxb2-maven-plugin
或其他任何东西.
JAXB2 Basics you're mentioning is not a property of maven-jaxb2-plugin
, it is a standalone set of JAXB 2.x plugins you can use with XJC - or jaxb2-maven-plugin
or whatever.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<arguments>
<argument>-Xequals</argument>
<argument>-XhashCode</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.11.1</version>
</dependency>
</dependencies>
</plugin>
我想问的是 - 为什么不直接使用 maven-jaxb2-plugin
?与 Codehaus 插件相比,它具有更多的功能 - 包括对 JAXB2 插件的配置支持.
What I wanted to ask - why not just use maven-jaxb2-plugin
? It has so much more functionality compared to the Codehaus plugin - including configuration support for JAXB2 plugins.
这篇关于使用 Mojo Jaxb2 maven 插件创建 Java 类时生成 hashCode() 和 equals()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!