# Extending OpenNLP

OpenNLP extensions allow customization of existing components. Most components define a factory class that can be implemented to control their creation. The implementation class must implement the required interface and have a public no-argument constructor.

## Extension Class Allowlist

Extension classes are loaded by `ExtensionLoader` via reflection. Only classes whose fully-qualified name starts with a registered package prefix are permitted. The default prefix is `opennlp.`, covering all built-in factories and serializers.

To use a custom class outside `opennlp.`, register its package before loading any model that references it:

    ExtensionLoader.registerAllowedPackage("com.example.nlp");

Alternatively, set the system property at JVM startup:

    -DOPENNLP_EXT_ALLOWED_PACKAGES=com.example.nlp.,com.other.factories.

A registered prefix can be removed with `ExtensionLoader.unregisterAllowedPackage(String)`.