Skip to content

Excluding Including Classes

Craftmaster2190 edited this page Jan 30, 2023 · 3 revisions

Excluding Including Classes

Enunciate does it's best to determine which classes are used to define your API by scanning the sourcepath and the classpath. Each Enunciate module gets the chance to look at each element on the path and determine whether the element should be included in the API. For example, the JAX-RS module assumes that any element annotated with @Path is to be included. When an element is included, Enunciate also aggressively and recursively includes any elements that are statically referenced by the included element.

Some modules have configurable inclusion policies. For example, the JAXB and Jackson modules by default only "passively" include elements, meaning elements are only included if they are referenced by another included element. For more information about how to configure the inclusion policy of various modules, see the respective module's documentation.

Sometimes Enunciate doesn't get it right and you have to explicitly configure Enunciate to include or exclude certain elements.

You can do this using any of the following methods:

Facets

See Facets for more information.

Configuration

You can exclude or include classes using the api-classes configuration element. This has the effect of including or excluding classes from all modules. However, if an excluded class is explicitly referenced by an included class, Enunciate will automatically include it (regardless of configuration) in order to avoid broken references.

Note also that the api-classes configuration element is used to determine which Java source files are to be included in the compilation. For more information, see Discovering Source Files.

<enunciate ...>
  ...
  <api-classes>
    <exclude pattern="com.mycompany.hide.**"/>
    <include pattern="com.mycompany.hide.ExceptThisClass"/>
    <exclude pattern="com.mycompany.api.MyClass"/>
  </api-classes>
  ...
</enunciate>

Note that includes take precedence over excludes:

<enunciate ...>
  ...
  <api-classes>
    <include pattern="com.mycompany.**"/>
    <exclude pattern="com.mycompany.ExceptThisClass"/>
    <!-- ^^^ Does NOT work ^^^ -->
  </api-classes>
  ...
</enunciate>

Annotations

You can annotate your class with @com.webcohesion.enunciate.metadata.Ignore. The annotated class will be ignored by all modules.

For example:

@com.webcohesion.enunciate.metadata.Ignore
public class FileUtils {

  //this is not a valid JAXB class because
  //it has a private constructor.
  private FileUtils() {
  }

  public static copyDir(File dir, File dest) {
    //implementation...
  }
}
Clone this wiki locally