Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Tip

Struts 1 provided a plugin class that provided listener-like capabilities. The Struts 2 plugins are like Eclipse or FireFox plugins, and not at all like Struts 1 "plugins".

The framework supports plugins that can be installed by adding a JAR file to the application's class path. To configure the plugin, the JAR may contain a struts-plugin.xml, 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.

Warning

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

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.

  1. struts-default.xml (bundled in the Core JAR)
  2. struts-plugin.xml (as many as can be found in other JARs)
  3. struts.xml (provided by the application)

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.

Plugin Examples

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

Sitemesh plugin

SiteMesh is a popular alternative to Tiles. SiteMesh provides a common look-and-feel to an application's pages by automatically wrapping a plain page with common elements like headers and menubars.

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

Code Block

 + META-INF/
   + manifest.mf
 + org
   + apache
     + struts2
       + sitemesh
         + FreeMarkerPageFilter.class
         + TemplatePageFilter.class
         + VelocityPageFilter.class

The SiteMesh Plugin doesn't need any configuration elements, like interceptors or results, and so it doesn't bother with a struts-plugin.xml.

Tiles plugin

Tiles is a popular alternative to SiteMesh. Tiles provides a common look-and-feel to an application's pages by breaking the page down into common fragments or "tiles".

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, it provides a
struts-plugin.xml file.

Bundled Plugins

Excerpt

Several plugins are available that extend the framework's capabilities.

IDE Plugins

...