问题描述
我正在使用maven jaxb2插件生成Java类,它是从jar中的模式构建的。但是,我不确定如何从绑定文件中正确定位这些模式。如果从jar中提取模式并将它们放在与绑定相同的目录中,那么一切都很好。但是,这不是一个实际的长期解决方案。
I'm using the maven jaxb2 plugin to generate Java classes, built from schemas in a jar. However, I'm not sure how to correctly locate to these schemas from a bindings file. If Iextract the schemas from the jar and drop them in the same directory as the bindings, all is well. However, this isn't a practical long term solution.
pom.xml:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemas>
<schema>
<dependencyResource>
<groupId>com.test</groupId>
<artifactId>schemas</artifactId>
<version>1.10-SNAPSHOT</version>
<resource>schemas/schema.xsd</resource>
</dependencyResource>
</schema>
</schemas>
<bindingDirectory>bindings</bindingDirectory>
<generatePackage>test.package</generatePackage>
<bindingIncludes>
<include>*.xml</include>
</bindingIncludes>
<extension>true</extension>
</configuration>
</plugin>
bindings.xml:
bindings.xml:
<jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb ./bindingschema_2_1.xsd"
version="2.1">
<jxb:bindings schemaLocation="classpath:/schemas/schema.xsd" node="/xs:schema">
<jxb:bindings node="//xs:complexType[@name='AbstractChangeable']">
<jxb:class implClass="com.test.AbstractEntity" />
</jxb:bindings>
</jxb:bindings>
推荐答案
我想在这里工作的是什么喜欢:
What I'd like to have working here is something like:
<jaxb:bindings schemaLocation="maven:org.jvnet.jaxb2.maven2:maven-jaxb2-plugin-tests-po!/purchaseorder.xsd" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="org.jvnet.jaxb2.maven2.tests.po"/>
</jaxb:schemaBindings>
</jaxb:bindings>
但目前还没有。请,我会尽力解决。
But it does not at the moment. Please file an issue, I'll try to fix it.
现在工作的是基于SCD的绑定:
What does work now is SCD-based binding:
<jaxb:bindings scd="x-schema::po" xmlns:po="urn:po">
<jaxb:schemaBindings>
<jaxb:package name="org.jvnet.jaxb2.maven2.tests.po"/>
</jaxb:schemaBindings>
</jaxb:bindings>
因此,您实际上不需要基于特定架构位置进行绑定,您可以基于命名空间URI,理论上更好。
So you don't actually need to bind based on a specific schema location, you can bind based on the namespace URI, which is theoretically better.
实际上,我有一种经验,即SCD绑定并不总能可靠地工作。
Practically I have an experience that SCD-bindings don't always work reliably.
更新
参见了解更多信息JAXB中的SCD使用情况。
See this link for more information SCD usage in JAXB.
这篇关于JAXB绑定到JAR中的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!