Plugins

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Struts

...

A Struts 2 plugin is a single JAR that contains 2 plugins contain classes and configuration that extend, replace, or add to existing Struts framework functionality. A plugin can be installed by adding a its JAR file to the application's class path, in addition to the JAR files to fulfill whatever dependencies the plugin itself may have. To configure the plugin, the JAR should contain a struts-plugin.xml file, which follows the same format as an ordinary struts.xml file.

...

Many popular but optional features of the framework are distributed as plugins. An application can retain all the plugins provided with the distribution, or just include the ones it uses. Plugins can be used to organize application code or to distribute code to third-parties.

Plugins are not loaded in any particular order. Plugins should not have dependencies on each other. A plugin may depend on classes provided by Struts Core, but it should not depend on classes loaded by another plugin.
Warning
Note

Packages defined in a plugin can have parent packages that are defined in another plugin. Plugins may define configuration elements with classes not contained in the plugin. Any classes not included in the plugin's JAR must be on the application's classpath at runtime. As from Struts 2.3.5

The framework loads its default configuration first, then any plugin configuration files found in others JARs on the classpath, and finally the "bootstrap" struts.xml.

...

Since the struts.xml file is always loaded last, it can make use of any resources provided by the plugins bundled with the distribution, or any other plugins available to an application.

Static resources

To include static resources in your plugins add them under "/static" in your jar. And include them in your page using "/struts" as the path, like in the following example:

Code Block
html
Assuming /static/main.css is inside a plugin jar, to add it to the page:

<@s.url value="/struts/main.css" var="css" />
<link rel="stylesheet" type="text/css" href="%{#css}" />

Read also StaticContentLoader JavaDoc.

Extension Points

Extension points allow a plugin to override a key class in the Struts framework with an alternate implementionimplementation. For example, a plugin could provide a new class to create Action classes or map requests to Actions.

...

Wiki Markup
{snippet:id=extensionPoints|javadoc=true|url=org.apache.struts2.config.BeanSelectionProviderDefaultBeanSelectionProvider}

Plugin Examples

Let's look at two similar but different plugins bundled with the core distribution.

...

The sitemesh-plugin.jar contains several classes, a standard JAR manifest, and a plugin configuration file.

Code Block
  + META-INF/
   + manifest.mf
 + org
   + apache
     + struts2
       + sitemesh
         + FreeMarkerPageFilter.class
         + TemplatePageFilter.class
         + VelocityPageFilter.class
 + struts-plugin.xml

...

The tiles-plugin.jar contains several classes, a standard JAR manifest, and a configuration file.

Code Block
  + META-INF/
   + manifest.mf
 + org
   + apache
     + struts2
       + tiles
         + StrutsTilesListener.class
         + StrutsTileUtilImpl.class
       + views
         + tiles
           + TilesResult.class
   + struts-plugin.xml

Since the Tiles Plugin does need to register configuration elements, a result class, it provides a struts-plugin.xml file.

Plugin Registry

(tick) For a list of bundled plugins, see the Plugin Reference Documentation. For more about bundled and third-party plugins, visit the Apache Struts Plugin Registry.

...