Class XjcMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="xjc",
          threadSafe=true,
          defaultPhase=GENERATE_SOURCES,
          requiresDependencyResolution=COMPILE)
    public class XjcMojo
    extends AbstractJavaGeneratorMojo

    Mojo that creates compile-scope Java source or binaries from XML schema(s) by invoking the JAXB XJC binding compiler. This implementation is tailored to use the JAXB Reference Implementation from project Kenai.

    Note that the XjcMojo was completely re-implemented for the 2.x versions. Its configuration semantics and parameter set is not necessarily backwards compatible with the 1.x plugin versions. If you are upgrading from version 1.x of the plugin, read the documentation carefully.

    See Also:
    The JAXB Reference Implementation
    • Field Detail

      • STALE_FILENAME

        public static final java.lang.String STALE_FILENAME
        The last part of the stale fileName for this XjcMojo.
        See Also:
        Constant Field Values
      • STANDARD_SOURCE_DIRECTORY

        public static final java.lang.String STANDARD_SOURCE_DIRECTORY

        Standard directory path (relative to basedir) searched recursively for source files (typically XSDs), unless overridden by an sources configuration element.

        See Also:
        Constant Field Values
      • STANDARD_SOURCE_EXCLUDE_FILTERS

        public static final java.util.List<Filter<java.io.File>> STANDARD_SOURCE_EXCLUDE_FILTERS

        Default exclude Filters for sources, used unless overridden by an explicit configuration in the xjcSourceExcludeFilters parameter. The default values are found as follows:

             
                 final List<Filter<File>> xsdTemp = new ArrayList<Filter<File>>();
                 xsdTemp.addAll(AbstractJaxbMojo.STANDARD_EXCLUDE_FILTERS);
                 xsdTemp.add(new PatternFileFilter(Arrays.asList("\\.xjb"), true));
                 STANDARD_SOURCE_EXCLUDE_FILTERS = Collections.unmodifiableList(xsdTemp);
             
         
        See Also:
        AbstractJaxbMojo.STANDARD_EXCLUDE_FILTERS
      • STANDARD_XJB_DIRECTORY

        public static final java.lang.String STANDARD_XJB_DIRECTORY

        Standard directory path (relative to basedir) searched recursively for XJB files, unless overridden by an xjbSources configuration element. As explained in the JAXB specification, XJB files (JAXB Xml Binding files) are used to configure parts of the Java source generation.

        See Also:
        Constant Field Values
      • STANDARD_XJB_EXCLUDE_FILTERS

        public static final java.util.List<Filter<java.io.File>> STANDARD_XJB_EXCLUDE_FILTERS

        Default List of exclude Filters for XJB files, unless overridden by providing an explicit configuration in the xjbExcludeSuffixes parameter. The default values are found as follows:

             
                 final List<Filter<File>> xjbTemp = new ArrayList<Filter<File>>();
                 xjbTemp.addAll(AbstractJaxbMojo.STANDARD_EXCLUDE_FILTERS);
                 xjbTemp.add(new PatternFileFilter(Arrays.asList("\\.xsd"), true));
                 STANDARD_XJB_EXCLUDE_FILTERS = Collections.unmodifiableList(xjbTemp);
             
         
        See Also:
        AbstractJaxbMojo.STANDARD_EXCLUDE_FILTERS
      • outputDirectory

        @Parameter(defaultValue="${project.build.directory}/generated-sources/jaxb",
                   required=true)
        private java.io.File outputDirectory

        Corresponding XJC parameter: d.

        The working directory where the generated Java source files are created.

      • sources

        @Parameter(required=false)
        private java.util.List<java.lang.String> sources

        Parameter holding List of XSD paths to files and/or directories which should be recursively searched for XSD files. Only files or directories that actually exist will be included (in the case of files) or recursively searched for XSD files to include (in the case of directories). Configure using standard Maven structure for Lists:

         
           <configuration>
           ...
               <sources>
                  <source>some/explicit/relative/file.xsd</source>
                  <source>/another/absolute/path/to/a/specification.xsd</source>
                  <source>a/directory/holding/xsds</source>
              </sources>
           </configuration>
         
         
        See Also:
        STANDARD_SOURCE_DIRECTORY
      • xjbSources

        @Parameter(required=false)
        private java.util.List<java.lang.String> xjbSources

        Parameter holding List of XJB Files and/or directories which should be recursively searched for XJB files. Only files or directories that actually exist will be included (in the case of files) or recursively searched for XJB files to include (in the case of directories). JAXB binding files are used to configure parts of the Java source generation. Supply the configuration using the standard Maven structure for configuring plugin Lists:

         
           <configuration>
           ...
               <xjbSources>
                  <xjbSource>bindings/aBindingConfiguration.xjb</xjbSource>
                  <xjbSource>bindings/config/directory</xjbSource>
              </xjbSources>
           </configuration>
         
         
        See Also:
        STANDARD_XJB_DIRECTORY
      • xjcSourceExcludeFilters

        @Parameter(required=false)
        private java.util.List<Filter<java.io.File>> xjcSourceExcludeFilters

        Parameter holding a List of Filters, used to match all files under the sources directories which should not be considered XJC source files. (The filters identify files to exclude, and hence this parameter is called xjcSourceExcludeFilters). If a file under any of the source directories matches at least one of the Filters supplied in the xjcSourceExcludeFilters, it is not considered an XJC source file, and therefore excluded from processing.

        If not explicitly provided, the Mojo uses the value within STANDARD_SOURCE_EXCLUDE_FILTERS. The algorithm for finding XJC sources is as follows:

        1. Find all files given in the sources List. Any Directories provided are searched for files recursively.
        2. Exclude any found files matching any of the supplied xjcSourceExcludeFilters List.
        3. The remaining Files are submitted for processing by the XJC tool.

        Example: The following configuration would exclude any sources whose names end with txt or foo:

             
                 <configuration>
                 ...
                      <xjcSourceExcludeFilters>
                          <filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
                              <patterns>
                                  <pattern>\.txt</pattern>
                                  <pattern>\.foo</pattern>
                              </patterns>
                          </filter>
                      </xjcSourceExcludeFilters>
                 </configuration>
             
         

        Note that inner workings of the Dependency Injection mechanism used by Maven Plugins (i.e. the DI from the Plexus container) requires that the full class name to the Filter implementation should be supplied for each filter, as is illustrated in the sample above. This is true also if you implement custom Filters.

        See Also:
        STANDARD_SOURCE_EXCLUDE_FILTERS, PatternFileFilter, AbstractPatternFilter, AbstractFilter
      • xjbExcludeFilters

        @Parameter(required=false)
        private java.util.List<Filter<java.io.File>> xjbExcludeFilters

        Parameter holding a List of Filters, used to match all files under the xjbSources directories which should not be considered XJB files. (The filters identify files to exclude, and hence this parameter is called xjbExcludeFilters). If a file matches at least one of the supplied Filters, it is not considered an XJB file, and therefore excluded from processing.

        If not explicitly provided, the Mojo uses the value within STANDARD_XJB_EXCLUDE_FILTERS.

        Example: The following configuration would exclude any XJB files whose names end with xml or foo:

             
                 <configuration>
                 ...
                      <xjbExcludeFilters>
                          <filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
                              <patterns>
                                  <pattern>\.txt</pattern>
                                  <pattern>\.foo</pattern>
                              </patterns>
                          </filter>
                      </xjbExcludeFilters>
                 ...
                 </configuration>
             
         

        Note that inner workings of the Dependency Injection mechanism used by Maven Plugins (i.e. the DI from the Plexus container) requires that the full class name to the Filter implementation should be supplied for each filter, as is illustrated in the sample above. This is true also if you implement custom Filters.

        See Also:
        STANDARD_XJB_EXCLUDE_FILTERS, PatternFileFilter, AbstractPatternFilter, AbstractFilter
      • skipXjc

        @Parameter(property="xjc.skip",
                   defaultValue="false")
        private boolean skipXjc
        Indicate if the XjcMojo execution should be skipped.
    • Constructor Detail

      • XjcMojo

        public XjcMojo()
    • Method Detail

      • shouldExecutionBeSkipped

        protected boolean shouldExecutionBeSkipped()
        Implement this method to check if this AbstractJaxbMojo should skip executing altogether.
        Specified by:
        shouldExecutionBeSkipped in class AbstractJaxbMojo
        Returns:
        true to indicate that this AbstractJaxbMojo should bail out of its execute method.
      • getSources

        protected java.util.List<java.net.URL> getSources()
        Override this method to acquire a List holding all URLs to the JAXB sources for which this AbstractJavaGeneratorMojo should generate Java files. Sources are assumed to be in the form given by the sourceType value.
        Specified by:
        getSources in class AbstractJavaGeneratorMojo
        Returns:
        A non-null List holding URLs to sources for the XJC generation.
        See Also:
        AbstractJavaGeneratorMojo.sourceType
      • getSourceXJBs

        protected java.util.List<java.io.File> getSourceXJBs()
        Override this method to retrieve a list of Files to all XJB files for which this AbstractJavaGeneratorMojo should generate Java files.
        Specified by:
        getSourceXJBs in class AbstractJavaGeneratorMojo
        Returns:
        A non-null List holding binding files.
      • getStaleFileName

        protected java.lang.String getStaleFileName()
        Retrieves the last name part of the stale file. The full name of the stale file will be generated by pre-pending "." + getExecution().getExecutionId() before this staleFileName.
        Specified by:
        getStaleFileName in class AbstractJaxbMojo
        Returns:
        The name of the stale file used by this AbstractJavaGeneratorMojo to detect staleness amongst its generated files.
      • getOutputDirectory

        protected java.io.File getOutputDirectory()
        Retrieves the directory where the generated files should be written to.
        Specified by:
        getOutputDirectory in class AbstractJaxbMojo
        Returns:
        the directory where the generated files should be written to.
      • getClasspath

        protected java.util.List<java.lang.String> getClasspath()
                                                         throws org.apache.maven.plugin.MojoExecutionException
        Retrieves the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read bytecode classes.
        Specified by:
        getClasspath in class AbstractJaxbMojo
        Returns:
        the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read classes.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if the classpath could not be retrieved.
      • addGeneratedSourcesToProjectSourceRoot

        protected void addGeneratedSourcesToProjectSourceRoot()
        Adds any directories containing the generated XJC classes to the appropriate Project compilation sources; either TestCompileSourceRoot or CompileSourceRoot depending on the exact Mojo implementation of this AbstractJavaGeneratorMojo.
        Specified by:
        addGeneratedSourcesToProjectSourceRoot in class AbstractJavaGeneratorMojo
      • addResource

        protected void addResource​(org.apache.maven.model.Resource resource)
        Adds the supplied Resource to the project using the appropriate scope (i.e. resource or testResource) depending on the exact implementation of this AbstractJaxbMojo.
        Specified by:
        addResource in class AbstractJaxbMojo
        Parameters:
        resource - The resource to add.