Skip to content

Specifying What To Compile

highsource edited this page Oct 21, 2014 · 10 revisions

TBD

Specifying schemas and bindings to compile

  • Specifying schemas
    • 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
    • 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