Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Tomcat Integration

Thomas Diesler edited this page Oct 11, 2013 · 16 revisions

Preparing Tomcat

Gravia provides a patch for for Tomcat as a Maven artefact

<dependency>
	<groupId>org.jboss.gravia</groupId>
	<artifactId>gravia-container-tomcat</artifactId>
	<classifier>patch</classifier>
	<type>zip</type>
</dependency>

It contains a number of jars that get copied to the common lib folder.

Preparing a WebApp

Gravia works with already resolved modules. In this case with the WebApp ClassLoader created by Tomcat.

Installing/Starting a Module

Before the WebApp becomes operational the target container (i.e. Tomcat) has to do the following

  1. Create the global Runtime instance
  2. Install the WebApp as a Module in the Runtime
  3. Start the WebApp Module

Stopping Stopping/Uninstalling a Module

When a WebApp gets undeployed the target container has to do the following

  1. Stop the WebApp Module
  2. Uninstall the WebApp Module from the Runtime

The Tomcat integration provides provides a ServletContextListener that does all of the above - add this to your WebApp.

Defining the Module

A Module combines a ClassLoader, a Resource and optional runtime headers. The Resource is the immutable set of Capabilities/Requirements associated with the Module. The ResourceIdentity is a mandatory capability for every Module.

There are various ResourceBuilders available.

To define a Module through its Manifest and install it to the Runtime you can do this

    Runtime runtime = RuntimeLocator.getRuntime();
    ResourceBuilder resbuilder = new ManifestResourceBuilder().load(manifest);
    ManifestHeadersProvider headers = new ManifestHeadersProvider(manifest);
    Module module = runtime.installModule(classLoader, resbuilder.getResource(), headers.getHeaders());

For this to work the manifest must define the Module's identity like this

Gravia-Identity: org.acme.webapp;version=1.0.0

Activating the Module

The Module headers may contain a Module-Activator entry that defines the FQN of a ModuleActivator.

In a manifest this can be defined like this

Module-Activator: org.acme.webapp.Activator

In the ModuleActivator you can register/lookup services, work with DS defined components, etc.

Clone this wiki locally