3

我试图让我的 pom.xml 在我的 JAXB 对象上生成 hashCode() 和 equals methods()。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>org.jvnet.jaxb2_commons</groupId>
        <artifactId>jaxb2-commons-lang</artifactId>
        <version>2.3</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.8.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <extension>true</extension>
                <args>
                    <arg>-XtoString</arg>
                    <arg>-Xequals</arg>
                    <arg>-XhashCode</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.6.2</version>
                    </plugin>
                </plugins>
            </configuration>
        </plugin>

    </plugins>
</build>

虽然这会产生以下错误......

package org.jvnet.jaxb2_commons.lang does not exist
package org.jvnet.jaxb2_commons.locator does not exist
package org.jvnet.jaxb2_commons.locator.util does not exist
cannot find symbol symbol: class Equals
cannot find symbol symbol: class HashCode
cannot find symbol symbol: class ToString
cannot find symbol symbol  : class ObjectLocator
cannot find symbol symbol  : class ToStringStrategy
cannot find symbol symbol  : class HashCodeStrategy

我用谷歌搜索过,我发现了一篇关于添加的帖子。

<dependency>
    <groupId>org.jvnet.jaxb2_commons</groupId>
    <artifactId>runtime</artifactId>
    <version>0.4.1</version>
</dependency>
<dependency>
    <groupId>org.jvnet.jaxb2_commons</groupId>
    <artifactId>testing</artifactId>
    <version>0.4.1</version>
    <scope>test</scope>
</dependency>

但这无济于事。

谁能帮帮我!

4

1 回答 1

19

这是我们正在使用的配置集。我相信有许多元素需要“排队”(可以这么说),否则你会得到错误指示。

一般依赖:-

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

maven-jaxb2-插件:-

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.8.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <extension>true</extension>
                <generatePackage>you.package.etc</generatePackage>
                <args>
                    <arg>-XtoString</arg>
                    <arg>-Xequals</arg>
                    <arg>-XhashCode</arg>
                    <arg>-Xinheritance</arg>
                    <arg>-Xcopyable</arg>
                    <arg>-XenumValue</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.6.4</version>
                    </plugin>
                </plugins>
            </configuration>
        </plugin>

绑定提取物:-

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
    jaxb:extensionBindingPrefixes="inheritance"
    jaxb:version="2.1">

......

<jaxb:bindings schemaLocation="yourschema.xsd" node="/xs:schema">
    <jaxb:bindings node="//xs:element[@name='element-you-want-to-have-interface']">
        <jaxb:class />
        <inheritance:implements>your.interface</inheritance:implements>
    </jaxb:bindings>
</jaxb:bindings>

......

</jaxb:bindings>
于 2013-06-06T15:19:37.507 回答