Skip to content

Specifying What To Compile

Paulo Eduardo Neves edited this page Apr 25, 2017 · 10 revisions

TBD

Specifying schemas and bindings to compile

Specifying schemas

<plugin>
    ...
    <configuration>
        <schemaDirectory>src/main/resources</schemaDirectory>
        <schemaIncludes>
	    <include>*.xsd</include>
        </schemaIncludes>
        <!-- By default, nothing is excluded. -->
        <schemaExcludes>
	    <exclude>*.xs</exclude>
        </schemaExcludes>
    </configuration>
</plugin>


<schemas>
	<schema>
		<!-- Specifies a schema from the Maven artifact. -->
		<dependencyResource>
			<groupId>org.jvnet.jaxb2.maven2</groupId>
			<artifactId>maven-jaxb2-plugin-tests-po</artifactId>
			<!--  Version of the artifact. May be omitted.
			The plugin will then try to find the version using
			the dependencyManagement and dependencies of the project. -->
			<version>${project.version}</version>
			<!-- Path of the resource within the artifact. -->
			<resource>purchaseorder.xsd</resource>
		</dependencyResource>
	</schema>
	<schema>
		<url>http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd</url>
	</schema>
	<schema>
		<!-- Specifies a schema in the Maven artifact. -->
		<url>maven:org.jvnet.jaxb2.maven2:maven-jaxb2-plugin-tests-po!/po.xsd</url>
	</schema>
	<schema>
		<fileset>
			<!-- Defaults to schemaDirectory. -->
			<directory>${basedir}/src/main/schemas</directory>
                        <!-- Defaults to schemaIncludes. -->
			<includes>
				<include>*.xsd</include>
			</includes>
			<!-- Defaults to schemaIncludes -->
			<excludes>
				<exclude>*.xs</exclude>
			</excludes>
		</fileset>
	</schema>
</schemas>

<!-- DTD, XMLSCHEMA, RELAXNG, RELAXNG_COMPACT, WSDL, AUTODETECT. -->
<schemaLanguage>AUTODETECT</schemaLanguage>
  • Basic usage, from directory:
    • schemaDirectory - Specifies the schema directory, src/main/resources by default.
    • schemaIncludes/include - Specifies file patterns to include as schemas. By default all *.xsd files will be included.
    • schemaExcludes/exclude - Specifies file patterns of schemas to exclude. By default, nothing is excluded.
  • Extended usage:
    • schemas/schema- Specifies schemas as filesets, URLs or Maven artifact resources.
      • dependencyResource - Specifies a schema from the Maven artifact.
        • groupId - Group id of the artifact, required.
        • artifactId - Artifact id of the artifact, required.
        • version - Version of the artifact. May be omitted. The plugin will then try to find the version using the dependencyManagement and dependencies of the project.
        • resource - Path of the resource within the artifact, for instance org/foo/bar/schema.xsd. Required. Do not include a leading /.
        • type - Type of the dependency, optional. Defaults to jar.
        • classifier - Classifier of the dependency, optional. Defaults to none.
    • url - Specifies a schema URL to compile.
    • fileset - Specifies a fileset to compile.
      • directory - Base directory of the fileset. Optional, defaults to schemaDirectory (see above).
      • includes/include - File patterns to include. Optional, defaults to schemaIncludes (see above).
      • excludes/exclude - File patterns to exclude. Optional, defaults to schemaExcludes (see above).
  • Specifying schema language:
    • schemaLanguage - Type of input schema language. One of: DTD, XMLSCHEMA, RELAXNG, RELAXNG_COMPACT, WSDL, AUTODETECT. If unspecified, it is assumed AUTODETECT.

Specifying bindings

<!-- Default to the schemaDirectory -->
<bindingDirectory>src/main/resources</bindingDirectory>
<bindingIncludes>
	<include>**/*.xjb</include>
</bindingIncludes>
<!-- By default, nothing is excluded. -->
<bindingExcludes>
	<exclude>**/*.xj</exclude>
</bindingExcludes>

<bindings>
	<binding>
		<dependencyResource>...</dependencyResource>
	</binding>
	<binding>
		<url>...</url>
	</binding>
	<binding>
		<fileset>
			<!-- Defaults to bindingDirectory. -->
			<directory>${basedir}/src/main/bindings</directory>
                        <!-- Defaults to bindingIncludes. -->
			<includes>
				<include>*.xjb</include>
			</includes>
			<!--  Defaults to bindingExcludes. -->
			<excludes>
				<exclude>*.xj</exclude>
			</excludes>
		</fileset>
	</binding>
</bindings>

<scanDependenciesForBindings>false</scanDependenciesForBindings>
  • Basic usage, from directory:
    • bindingDirectory - Specifies the binding directory, default to the schemaDirectory.
    • bindingIncludes/include - Specifies file patterns to include as bindings. By default all *.xjb files will be included.
    • bindingExcludes/exclude - Specifies file patterns of bindings to exclude. By default, nothing is excluded.
  • Extended usage:
    • bindings/binding- Specifies bindings as filesets, URLs or Maven artifact resources.
      • dependencyResource - Specifies a binding from the Maven artifact.
        • groupId - Group id of the artifact, required.
        • artifactId - Artifact id of the artifact, required.
        • version - Version of the artifact. May be omitted. The plugin will then try to find the version using the dependencyManagement and dependencies of the project.
        • resource - Path of the resource within the artifact, for instance org/foo/bar/binding.xjb. Required. Do not include a leading /.
        • type - Type of the dependency, optional. Defaults to jar.
        • classifier - Classifier of the dependency, optional. Defaults to none.
    • url - Specifies an URL of the binding to use.
    • fileset - Specifies a fileset of bindings to use.
      • directory - Base directory of the fileset. Optional, defaults to bindingDirectory (see above).
      • includes/include - File patterns to include. Optional, defaults to bindingIncludes (see above).
      • excludes/exclude - File patterns to exclude. Optional, defaults to bindingExcludes (see above).

Below is an example of a non-standard directory layout configuration:

<configuration>
	<!-- Changes the default schema directory -->
	<schemaDirectory>src/main/schema</schemaDirectory>
	<schemaIncludes>
		<include>one/*/*.xsd</include>
	</schemaIncludes>			
	<schemaExcludes>
		<exclude>one/two/*.xsd</exclude>
	</schemaExcludes>			
	<bindingDirectory>src/main/binding</bindingDirectory>
	<bindingIncludes>
		<include>one/*/*.xjb</include>
	</bindingIncludes>			
	<bindingExcludes>
		<exclude>one/two/*.xjb</exclude>
	</bindingExcludes>			
</configuration>

Specifying URLs, filesets and Maven artifact resources

Since 0.8.0.

You can specify schemas and bindings as URLs, filesets and Maven artifact resources using schemas/schema and bindings/binding configuration elements:

<configuration>                                                                                         
	<forceRegenerate>true</forceRegenerate>                                                         
	<schemas>                                                                                       
		<!--
			Compiles a schema from the URL.
			It is highly recommended to make local copies
			and use a catalog file to "rewrite" absolute URLs
			to the local files.
		-->
		<schema>                                                                                
			<url>http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd</url>          
		</schema>                                                                                
		<!--
			Compiles a schema which resides
			in another Maven artifact.
		-->
		<schema>                                                                                
			<dependencyResource>                                                            
				<groupId>org.jvnet.jaxb2.maven2</groupId>                               
				<artifactId>maven-jaxb2-plugin-tests-po</artifactId>                    
				<!-- Can be defined in project dependencies or dependency management -->
				<version>${project.version}</version>                                   
				<resource>purchaseorder.xsd</resource>                                  
			</dependencyResource>                                                           
		</schema>
		<!--
			Compiles a fileset.
		-->
		<schema>                                                                                
			<fileset>                                                                       
				<!-- Defaults to schemaDirectory -->                                    
				<directory>${basedir}/src/main/schemas</directory>                                 
				<!-- Defaults to schemaIncludes -->                                     
				<includes>                                                              
					<include>*.*</include>                                          
				</includes>                                                             
				<!-- Defaults to schemaExcludes -->                                     
				<excludes>                                                              
					<exclude>*.xs</exclude>                                         
				</excludes>                                                             
			</fileset>                                                                      
		</schema>                                                                                
	</schemas>                                                                                      
</configuration>                                                                                        

The same works for bindings and catalogs (see Using Catalogs).

Compiling a schema from a Maven artifact

<configuration>                                                                                         
	<forceRegenerate>true</forceRegenerate>                                                         
	<schemas>                                                                                       
		<schema>
			<dependencyResource>                                                            
				<groupId>org.jvnet.jaxb2.maven2</groupId>                               
				<artifactId>maven-jaxb2-plugin-tests-po</artifactId>                    
				<!-- Can be defined in project dependencies or dependency management -->
				<version>${project.version}</version>                                   
				<resource>purchaseorder.xsd</resource>                                  
			</dependencyResource>                                                           
		</schema>                                                                               
	</schemas>                                                                                      
</configuration>                                                                                        

See also the Modular Schema Compilation guide.

Compiling a schema from an URL

<configuration>
	<forceRegenerate>true</forceRegenerate>
	<schemas>
		<schema>
			<url>http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd</url>
		</schema>
	</schemas>
</configuration>

It is highly recommended to make a local copy of the external schema and use a catalog file to rewrite the absolute URL (or a namespace) to the local copy. Otherwise your will depend on external resources during the build, which is definitely not a good idea.

You also have to use forceRegenerate' 'true in this case, since the plugin can't generally detect if external resources were changed or not.

Clone this wiki locally