问题
I have 2 schemas A, B. I'm reusing some A elements in B.
I do not use namespaces.
I'm using
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.9.0</version>
I have have defined an inclusion of schema A in schema B as:
<xs:include schemaLocation="classpath:my.schema.A.xsd"/>
and the catalog as
REWRITE_SYSTEM "classpath:my.schema.A.xsd" "maven:my.schema:schema-a!/A.xsd"
The jaxb configuration goes:
<configuration>
<generatePackage>my.schema.b</generatePackage>
<schemaIncludes>
<includes>B.xsd</includes>
</schemaIncludes>
<episodes>
<episode>
<groupId>my.schema</groupId>
<artifactId>schema-a</artifactId>
</episode>
</episodes>
<catalog>src/main/catalog/catalog.cat</catalog>
</configuration>
The issue is that whenever I specify the episode dependency the schema does not generate any classes even though it contains some B elements I want to generate the classes for.
[INFO] Parsing input schema(s)...
[INFO] Compiling input schema(s)...
[INFO] Cleaning package directories.
[INFO] Finished execution.
When I remove the episode it works well and generates classes for schema A as well - which I indeed want to avoid.
Do you have any suggestions?
A sample was published in Jaxb episodic compilation
回答1:
Ok, I've checked your example. The problem is that you don't use namespaces.
Check your META-INF/sub-jaxb.episode
file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:bindings scd="x-schema::">
<jaxb:schemaBindings map="false">
<jaxb:package name="schema.episode.a"/>
</jaxb:schemaBindings>
<jaxb:bindings scd="person">
<jaxb:class ref="schema.episode.a.Person"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
You see this <jaxb:bindings scd="x-schema::">
and then <jaxb:schemaBindings map="false">
. This basically tells XJC "don't map anything in the empty namespace". Since your second schema (b.xsd
) also does not use namespaces, when you use a.xsd
's episode file (binding above), you suppress generation of code for b.xsd
as well.
To sum it up, when using episodes/separate schema compilation you can't put schemas with one namespace into different episodes. This is exactly the issue with include
.
This is not a bug in the maven-jaxb2-plugin
. I would not also call it a bug in XJC. It's just how episodes work by default.
See my pull request here, it demonstrates episodic compilation, when namespaces are handled accordingly.
回答2:
Author of the maven-jaxb2-plugin
here.
My guess would be that your episode says something like "don't compile namespaces A and B". Please check the binding file inside META-INF
in your JAR.
This is pretty advanced usage, there's quite a number of points where this can go wrong. You use:
- catalogs
- Maven artifact-based schema resolution
- episodes
Catalogs and episodes are XJC features, Maven resolution comes from the maven-jaxb2-plugin
.
We should try to single out what fails:
- Try it just with episodes - extract your schemas and compile "as is", without catalogs and resolver
- Just catalogs - extract schema and rewrite to local dirs instead of
maven:
- Try
maven:my.schema:schema-a!/A.xsd
as schema location without episodes and catalogs
Obviously another three combinations to try.
If you provide a sample project, I'll investigate (but not within the next 10 days). The best would be to file an issue. I'll be moving the plugin to GitHub so this would be a good place:
https://github.com/highsource/maven-jaxb2-plugin
来源:https://stackoverflow.com/questions/25728801/jaxb-episode-compilation-with-include-does-not-work