[英]xjc fails to generate classes when using bindings
這曾經適用於所有以前版本的 JAXB。 我已經升級到 JAXB 的 2.2.7 版,現在xjc
拋出以下內容:
java.lang.AssertionError: javax.xml.bind.JAXBException - 有鏈接異常:[com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
com.sun.xml.bind.api.impl.NameConverter 是一個接口,JAXB 不能處理接口。 此問題與以下位置有關:在 com.sun.xml.bind.api.impl.NameConverter 在公共 com.sun.xml.bind.api.impl.NameConverter com.sun.tools.xjc.reader.xmlschema。 bindinfo.BIGlobalBinding.nameConverter at com.sun.tools.xjc.reader.xmlschema.bindinfo.BIGlobalBinding]
從 jaxb 2.2.7 開始,他們將 jaxb 庫拆分為幾個組件。 xjc 現在與任何特定的 jaxb 運行時分離。 要解決此問題,請確保在執行 xjc 時在類路徑上提供 jaxb 運行時。 詳細信息可以在他們的發行說明中找到: https : //jaxb.java.net/nonav/2.2.7/docs/release-documentation.html#a-2-2-7
參考實現可以在 maven central 上找到,坐標如下:com.sun.xml.bind:jaxb-impl:2.2.7
由於整個 JAXB 項目現在從https://github.com/javaee/jaxb-v2移動到https://github.com/eclipse-ee4j/jaxb-ri包括 Maven 依賴項,我更新了我的pom.xml
從
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>${jaxb-xjc.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>${jaxb.version}</version>
</dependency>
到
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>${jaxb-xjc.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-core</artifactId>
<version>${jaxb.version}</version>
</dependency>
這至少幫助我解決了類似的問題。
假設您使用的是 Eclipse 或衍生產品(websphere studio、jDeveloper、Spring Tools Suite 等)。 如果沒有,您可以使用 JDK 'xjc' 命令行工具,否則使用Maven 插件 JAXB2 )
您必須為項目顯式配置 JAXB(不同的項目可能具有不同的配置以使事情變得簡單!)
在最近的 Eclipse 版本 (4.4+) 中,請遵循以下步驟:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.