gpt4 book ai didi

JAXB - schemaBindings 定制不与任何模式元素相关联

转载 作者:行者123 更新时间:2023-12-04 15:13:01 24 4
gpt4 key购买 nike

我正在尝试使用带有自定义绑定(bind)的 Maven XJC 插件从一组 XSD 文件中生成 Java 类。自定义添加到 prefix JAXB generated classes .然而,当 maven 构建运行时,XJC 插件似乎无法识别 schemaBindings。元素并抛出异常如下。

[ERROR] Error while parsing schema(s).Location [ file:/C:/blah/bindings.xjb{5,25}].
com.sun.istack.SAXParseException2: The "jaxb:schemaBindings" customization is no
t associated with any schema element.
at com.sun.tools.xjc.reader.internalizer.Internalizer.reportError(Intern
alizer.java:632)
at com.sun.tools.xjc.reader.internalizer.Internalizer.reportError(Intern
alizer.java:626)
at com.sun.tools.xjc.reader.internalizer.Internalizer.move(Internalizer.
java:451)
at com.sun.tools.xjc.reader.internalizer.Internalizer.transform(Internal
izer.java:160)
at com.sun.tools.xjc.reader.internalizer.Internalizer.transform(Internal
izer.java:109)
at com.sun.tools.xjc.reader.internalizer.DOMForest.transform(DOMForest.j
ava:449)
at com.sun.tools.xjc.ModelLoader.buildDOMForest(ModelLoader.java:345)
at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:377)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:174)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:119)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.loadModel(XJC22Mojo.java:45)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:35)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:22)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:282)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:147)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLi
fecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:535)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
ts(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:6
0)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

bindings.jxb 如下。
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.1" schemaLocation="blah.xsd">
<jaxb:schemaBindings>
<jaxb:nameXmlTransform>
<jaxb:elementName suffix="Type"/>
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
</jaxb:bindings>

以下插件用于生成 Java 类。粘贴相关 mvn片段在这里。
<plugin>   

<groupId>org.jvnet.jaxb2.maven2</groupId>

<artifactId>maven-jaxb2-plugin</artifactId>

<version>0.8.0</version>

<executions>

<execution>

<goals>

<goal>generate</goal>

</goals>
</execution>

</executions>

<dependencies>

<dependency>

<groupId>com.sun.xml.bind</groupId>

<artifactId>jaxb-xjc</artifactId>

<version>2.2.6</version>

</dependency>

<dependency>

<groupId>com.sun.xml.bind</groupId>

<artifactId>jaxb-impl</artifactId>

<version>2.2.6</version>

</dependency>

</dependencies>
<configuration>

<schemaDirectory>./src/main/resources</schemaDirectory>

<includeBindings>
<includeBinding>**/*.xjb</includeBinding>
</includeBindings>
<extension>true</extension>

</configuration>

</plugin>

only other discussion I could find on this issue revolves about JAX-WS我不使用它,因为这里没有涉及 WSDL 文件。这里都是 XSD 文件。

我不明白为什么必须发生此错误,因为 JAXB 的 binding.xsd文件确实定义了 schemaBindings元素如下所示。
<xs:element name="schemaBindings" substitutionGroup="jaxb:declaration">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="jaxb:package"/>
<xs:element minOccurs="0" ref="jaxb:nameXmlTransform"/>
</xs:sequence>
<xs:attribute name="map" type="xs:boolean" />
</xs:complexType>
</xs:element>

非常感谢有关此问题的任何提示。如果需要更多输入,请告诉我。谢谢!

编辑:
Internet 上的很多人似乎都毫无问题地使用了 schemaBindings。这可能是问题中提到的依赖项的问题吗?

最佳答案

您的 jaxb:schemaBindings必须将绑定(bind)与某个模式架构相关联。通过模式位置或 scd。
请看 http://jaxb.java.net/guide/Customizing_Java_packages.html

关于JAXB - schemaBindings 定制不与任何模式元素相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15230503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com