为什么JAXB说" xxx是一个接口,而JAXB无法处理接口&QUOT ;.尽管所产生的类不是一个接口 [英] Why does JAXB say "xxx is an interface, and JAXB can't handle interfaces". Even though the generated class is not an interface

查看:3843
本文介绍了为什么JAXB说" xxx是一个接口,而JAXB无法处理接口&QUOT ;.尽管所产生的类不是一个接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用JAXB绑定我的XSD的,然后试图创建的JAXBContext:

I used JAXB to bind my xsd's and then tried creating the JAXBContext:

JAXBContext jaxbContext = JAXBContext.newInstance("my package name");

但JAXB提供180 IllegalAnnotationsException。

But JAXB gives 180 IllegalAnnotationsException.

大多数异常有以下信息:

Most of the exceptions have the following messages:


  1. XXX是一个接口和JAXB不能处理接口

  2. XXX没有一个无参数的默认构造函数

  3. @ XmlAttribute / @ XmlValue需要引用映射为XML文本Java类型。

当我看着类生成没有一个是接口,我不明白为什么JAXB是间preting他们作为接口。

When I look at the classes generated none of them are interfaces and I can't understand why JAXB is interpreting them as interfaces.

下面的是JAXB报告的错误之一的堆栈跟踪:

Here's is the stack trace of one of the errors reported by JAXB :

com.sc.md.datatypes.schemas.csemessage.EnvelopeType is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
    at com.sc.md.datatypes.schemas.csemessage.EnvelopeType
    at protected com.sc.md.datatypes.schemas.csemessage.EnvelopeType com.sc.md.datatypes.schemas.csemessage.cseMessage.envelope
    at com.sc.md.datatypes.schemas.csemessage.cseMessage
com.sc.md.datatypes.schemas.csemessage.EnvelopeType does not have a no-arg default constructor.
this problem is related to the following location:
    at com.sc.md.datatypes.schemas.csemessage.EnvelopeType
    at protected com.sc.md.datatypes.schemas.csemessage.EnvelopeType com.sc.md.datatypes.schemas.csemessage.cseMessage.envelope
    at com.sc.md.datatypes.schemas.csemessage.cseMessage

这是该类型在如何定义的xsd:

And this is how the type is defined in xsd :

<xs:complexType name="EnvelopeType">
    <xs:sequence>
        <xs:element name="Sent" type="DateTimeType"/>
        <xs:element name="Identifier" type="String_1_14"/>
        <xs:element name="AcknowledgementCode" type="AcknowledgementCodeType"/>
    </xs:sequence>

<xs:simpleType name="AcknowledgementCodeType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="m"/>
        <xs:enumeration value="p"/>
    </xs:restriction>
</xs:simpleType>

下面是我用于产生结合的pom.xml

Here is the pom.xml I have used to generate the binding :

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cs</groupId>
<artifactId>cs-jaxb</artifactId>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.4-1</version>
    </dependency>
</dependencies>
<name>cs jaxb</name>
<version>1.0.0</version>
<parent>
    <artifactId>hip-jaxb-parent</artifactId>
    <groupId>com.cs</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<build>
    <defaultGoal>install</defaultGoal>
    <plugins>
        <plugin>

            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.8.0</version>
            <executions>
                <execution>

                    <id>CS</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <schemaDirectory>src/main/resources/</schemaDirectory>
                        <schemaIncludes>
                            <include>**/*.xsd</include>
                        </schemaIncludes>

                    </configuration>
                </execution>

            </executions>
        </plugin>
        <plugin>
            <inherited>true</inherited>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

自其第一次请耐心等待我,我问在网络上的一个问题:)

Please be patient with me since its the first time I'm asking a question on the web :)

推荐答案

感谢所有,这是因为在我的部分通常一个很大的错误,但反正我喜欢用计算器,第一次,并会做出点窥探在这里。

Thanks to all, it was as usual a big mistake on my part, but anyways I enjoyed using stackoverflow for the first time and will make a point to snoop around here.

问题是我classpath.I指的是一个XMLBeans的结合项目,该项目曾与同一个包和类由JAXB生成的那些,它被列为我的类路径一罐Java源代码。
所以我不得不2班具有相同名称和包装,但我的痛苦JAXB被采摘XMLBeans的类,我不知道,2 days.This是Java最古老的错误之一,我对任何人都blunder.If道歉需要任何澄清,请删除一个评论。

The problem was with my classpath.I was referring to a xmlbeans binding project, which had the java source with the same package and classes as the ones generated by jaxb, which were included as a jar on my classpath. So I had 2 classes with same name and package, but to my misery JAXB was picking the Xmlbeans class and I didn't realise that for 2 days.This is one of the oldest errors in Java and I apologise for the blunder.If anyone needs any clarification please drop a comment.

这篇关于为什么JAXB说&QUOT; xxx是一个接口,而JAXB无法处理接口&QUOT ;.尽管所产生的类不是一个接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆