如何使JAXB注释并提供equlas / hash代码实现

我正在尝试使用JAXB从WSDL生成类,这些类使用Jsr303Annotations进行注释,并提供equals和hashcode的实现.

这两个都是分开工作,但是当我尝试实现这两个要求时,我得到错误:

在“构建工作区”期间发生内部错误.
com.sun.tools.xjc.Plugin:Provider org.jvnet.jaxb2_commons.plugin.fixjaxb1058.FixJAXB1058Plugin无法实例化:java.lang.NoClassDefFoundError:org / jvnet / jaxb2_commons / reflection / util / Accessor

有人可以告诉我如何配置JAXB来做这两件事吗?

贝娄是我尝试这样做的:

<plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-wsdl</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <schemaDirectory>src/main/resources</schemaDirectory>
                            <schemaIncludes>
                                <include>*.wsdl</include>
<!--                                <include>*.xsd</include> -->
                            </schemaIncludes>
<!--                            <forceRegenerate>true</forceRegenerate> -->
                            <!-- <removeOldOutput>true</removeOldOutput> -->
                            <!-- <cleanPackageDirectories>true</cleanPackageDirectories> -->
                            <strict>true</strict>
                            <extension>true</extension>
                            <args>
                                <arg>-XJsr303Annotations</arg>
                                <arg>-Xannotate</arg>
                                <arg>-Xequals</arg>
                                <arg>-XhashCode</arg>
                            </args>
                            <plugins>
                                <plugin>
                                <groupId>org.jvnet.jaxb2_commons</groupId>
                                <artifactId>jaxb2-basics-annotate</artifactId>
                                <version>0.6.3</version>
                                </plugin>
                                <plugin>
                                    <groupId>org.jvnet.jaxb2_commons</groupId>
                                    <artifactId>jaxb2-basics</artifactId>
                                    <version>0.9.4</version>
                                </plugin>
                                <plugin>
                                    <groupId>com.github.krasa</groupId>
                                    <artifactId>krasa-jaxb-tools</artifactId>
                                    <version>1.1</version>
                                </plugin>
                            </plugins>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

编辑:我尝试使用的相关依赖项:

        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics-runtime</artifactId>
            <version>0.9.4</version>
        </dependency>

<!--        <dependency> -->
<!--            <groupId>org.jvnet.jaxb2_commons</groupId> -->
<!--            <artifactId>jaxb2-basics-annotate</artifactId> -->
<!--            <version>1.0.0</version> -->
<!--        </dependency> -->


<!--        <dependency> -->
<!--        <groupId>org.jvnet.jaxb2_commons</groupId> -->
<!--        <artifactId>jaxb2-commons-lang</artifactId> -->
<!--        <version>2.3</version> -->
<!--        </dependency> -->

只有equals / hash代码的第一个依赖项和插件的组合才会产生结果.

如果我包含其他2个依赖项,那么我会在项目中为每个依赖项丢失artifact -id消息.

当没有equals / hashcode插件使用时,注释插件在没有显式依赖的情况下工作,反之亦然.

编辑:最终解决方案,以防任何人陷入同样的​​问题

因此,需要将注释和equals / hash代码插件分离为单独的执行,这解决了所有问题.

最佳答案 找到了解决方案.这个插件需要另一个依赖:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.12.3</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>                             
        <generatePackage>com.argonio.fias.entity</generatePackage>                       
        <schemaDirectory>src/main/resources/xsd</schemaDirectory>
        <readOnly>true</readOnly>
        <removeOldOutput>true</removeOldOutput>
        <verbose>true</verbose>
        <extension>true</extension>
        <args>
            <arg>-no-header</arg>
            <arg>-Xxew</arg>
            <arg>-Xxew:instantiate lazy</arg>
            <arg>-Xxew:plural</arg>
            <arg>-Xequals</arg>
        </args>
        <plugins>
            <plugin>
                <groupId>com.github.jaxb-xew-plugin</groupId>
                <artifactId>jaxb-xew-plugin</artifactId>
                <version>1.5</version>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics</artifactId>
                <version>0.9.4</version>
            </plugin>
        </plugins>
    </configuration>
    <dependencies>
        <!-- This dependency is required to execute the plugin -->
        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics-tools</artifactId>
            <version>0.9.4</version>
        </dependency>
    </dependencies>
</plugin>
点赞