-
Notifications
You must be signed in to change notification settings - Fork 103
Using Episodes
Also known as Separate schema compilation.
If you're compiling large sets of schemas (like the [OGC Schemas|http://ogc.java.net]) you may probably want to compile the
schemas separately. For instance, if you have two schemas A and B (where B imports A), you may want to compile them
into two artifacts A.jar and B.jar such that:
- Classes relevant to
Areside in theA.jarartifact. - Classes relevant to
B(and only those classes) reside in theB.jarartifact. - The
A.jarartifact is the dependency of theB.jarartifact.
This task is called the separate or episodic compilation. Kohsuke described it in [his blog|http://weblogs.java.net/blog/kohsuke/archive/2006/09/separate_compil.html].
JAXB2 Maven Plugin supports episodic compilation via the following configuration parameters:
-
episode- Iftrue, the episode file (describing mapping of elements and types to classes for the compiled schema) will be generated. -
episodeFile- Target location of the episode file. By default it istarget/generated-sources/xjc/META-INF/sun-jaxb.episodeso that the episode file will appear asMETA-INF/sun-jaxb.episodein the JAR - just as XJC wants it. -
episodes/episode- If you want to use existing artifacts as episodes for separate compilation, configure them asepisodes/episodeelements. It is assumed that episode artifacts contain an appropriateMETA-INF/sun-jaxb.episoderesource.-
groupId- Group id of the episode artifact, required. -
artifactId- Id of the episode artifact, required. -
version- Version of the episode artifact. May be omitted. The plugin will then try to find the version using thedependencyManagementanddependenciesof the project. -
type- Type of the episode artifact, optional. Defaults tojar. -
classifier- Classifier of the episode artifact, optional. Defaults to none.
-
-
useDependenciesAsEpisodes- Use all of the compile-scope project dependencies as episode artifacts. It is assumed that episode artifacts contain an appropriateMETA-INF/sun-jaxb.episoderesource. Default is false.
For example, consider that we've built the A schema as com.acme.foo:a-schema:jar:1.0 artifact and want to use it as an episode when we compile the B schema.
Here's how we configure it:
<project ...>
...
<dependencies>
...
<dependency>
<groupId>com.acme.foo</groupId>
<artifactId>a-schema</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<extension>true</extension>
<useDependenciesAsEpisodes>true</useDependenciesAsEpisodes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Alternatively you can specify episode artifacts explicitly:
```xml
<project ...>
...
<dependencies>
...
<dependency>
<groupId>com.acme.foo</groupId>
<artifactId>a-schema</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<extension>true</extension>
<episodes>
<episode>
<groupId>com.acme.foo</groupId>
<artifactId>a-schema</artifactId>
<!-- Version is not required if the artifact is
configured as dependency -->
</episode>
</episodes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>In this case JAXB will not generate classes for the imported A schema. The B.jar artifact will only contain classes relevant to the schema B.
See the [sample episode project|sample episode project] for example.
Note that JAXB still needs to access BOTH A and B schemas during the compilation. And you probably don't want to manually copy or duplicate schemas.
One way to solve this is to use the maven-dependency-plugin
to unpack the required schema from schema-a.jar.
A much better way is to use a catalog to resolve schema-a.xsd into a resource inside the Maven artifact schema-a:
REWRITE_SYSTEM "http://www.acme.com/foo/a.xsd" "maven:com.acme.foo:a-schema!/"
<configuration>
<catalog>src/main/resources/catalog.cat</catalog>
</configuration>A combination of episodes, catalogs and referencing resources in maven Artifacts allows fully modular schema compilation. Please see the Modular Schema Compilation guide.
- Home
- Migration guide
-
JAXB Maven Plugin
- Quick Start
-
User Guide
- Basic Usage
- Specifying What To Compile
- Referencing Resources in Maven Artifacts
- Using Catalogs
- Using Episodes
- Modular Schema Compilation
- Controlling the Output
- Using JAXB Plugins
- Using a Specific JAXB Version
- Configuring Extension, Validation and XML Security
- IDE Integration
- Miscellaneous
- Configuring Proxies
- Maven Documentation
- Configuration Cheat Sheet
- Common Pitfalls and Problems
-
JAXB2 Basics Plugins
- Using JAXB2 Basics Plugins
- JSR-305 Support
-
JAXB2 Basics Plugins List
- SimpleEquals Plugin
- SimpleHashCode Plugin
- Equals Plugin
- HashCode Plugin
- ToString Plugin
- Copyable Plugin
- Mergeable Plugin
- Inheritance Plugin
- AutoInheritance Plugin
- Wildcard Plugin
- Setters Plugin
- Simplify Plugin
- EnumValue Plugin
- JAXBIndex Plugin
- FixJAXB1058 Plugin
- Commons Lang Plugin
- Default Value Plugin
- Fluent API Plugin
- Namespace Prefix Plugin
- Value Constructor Plugin
- Boolean Getter Plugin
- CamelCase Plugin
- XML ElementWrapper Plugin
- Parent Pointer Plugin
- Property Listener Injector Plugin
- Annox
- JAXB Annotate Plugin
-
HyperJAXB3
- Build System Support
- Customization Guide
- Databases
- Development guide
- Extension guide
- FAQ
- IDE Support
- Java Persistence
- JAXB
- JDK Support
- Project Templates
-
Reference
- Adding vendor-specific annotations
- Features
- Integrating Hyperjaxb3 in builds
- Introduction
- Making schema-derived classes ready for JPA
- Adding required properties
- Applying workarounds for JAXB vs. JPA conflicts
- Enforcing top-level classes
- Generating equals and hashCode methods
- Generating ORM metadata
- Generating persistence unit descriptor
- JPA 2 Support
- Making classes serializable
- Testing generated mappings
- Reference - single page
- Related Projects
- Sample projects
- Solutions
- Target Scenarios
- Test Projects
- Tutorials
- Best Practices
- FAQ
- Sample Projects
- Support
- License
- Distribution