JAXB を使用して xsd をバインドし、JAXBContext を作成しようとしました。
JAXBContext jaxbContext = JAXBContext.newInstance("my package name");
しかし、JAXB は 180 IllegalAnnotationsException を返します。
ほとんどの例外には、次のメッセージがあります。
- XXX はインターフェイスであり、JAXB はインターフェイスを処理できません
- XXX には引数なしのデフォルト コンストラクタがありません
- @XmlAttribute/@XmlValue は、XML のテキストにマップされる Java 型を参照する必要があります。
生成されたクラスを見ると、どれもインターフェースではなく、なぜ JAXB がそれらをインターフェースとして解釈するのか理解できません。
以下は、JAXB によって報告されたエラーの 1 つのスタック トレースです。
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 でのタイプの定義方法です:
<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 は次のとおりです。
<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>
ネットで質問するのは初めてなので気長にお待ちください:)