Skip to main content

Plugin Definition and Development

This page describes how to define extension points, implement plugins, package them, and call them from the host application.

The current recommended split is:

  1. contract layer
  2. implementation layer

Contract Layerโ€‹

Shared extension contracts should live in:

  • geelato-plugin-all

This layer normally contains:

  • PluginExtensionPoint
  • business extension interfaces
  • shared DTOs and metadata classes

Implementation Layerโ€‹

Concrete plugin modules live in projects such as:

  • geelato-example-plugin
  • geelato-ocr-plugin

They typically contain:

  • plugin main class
  • plugin Spring configuration
  • extension implementation classes
  • plugin.properties

Main Stepsโ€‹

1. Define an Extension Interfaceโ€‹

Example:

public interface Greeting extends PluginExtensionPoint {
String getGreeting();
}

2. Implement the Plugin Main Classโ€‹

The current example uses SpringPlugin and creates its own Spring ApplicationContext.

3. Add Plugin Spring Configurationโ€‹

Example plugin configuration provides plugin-local beans such as GreetingService.

4. Implement the Extensionโ€‹

Add @Extension to the concrete class so PF4J can discover it.

5. Provide plugin.propertiesโ€‹

The current example contains:

  • plugin.class
  • plugin.dependencies
  • plugin.id
  • plugin.provider
  • plugin.version

6. Package the Pluginโ€‹

The plugin module should:

  • depend on plugin-all
  • enable org.pf4j.processor.ExtensionAnnotationProcessor
  • write plugin metadata into the jar manifest

After packaging, the jar should contain:

  • META-INF/extensions.idx
  • META-INF/MANIFEST.MF
  • plugin.properties

Host-Side Invocationโ€‹

The host application should use:

  • PluginBeanProvider

Example:

Greeting greeting = pluginBeanProvider.getBean(Greeting.class, "example-plugin");
String result = greeting.getGreeting();

If no matching extension is found, the runtime throws:

  • UnFoundPluginException

Suggested Readingโ€‹