11.5. Forcing Web Application Deployment to Tomcat or Jetty

Typically, a web application deployment plan uses the format described above, and therefore it can be deployed in a Geronimo configuration running either Jetty or Tomcat as the web container. If container-specific settings are necessary, they can be located in the container-config element for one or both web containers (see Section 11.3.3, “Web Container-specific Configuration”).

However, in some cases, it may be desirable to restrict the web application to deploy only in Tomcat or only in Jetty. In that case, a different namespace should be used for the entire deployment plan, one of:

Additionally, instead of including a container-config element, any of the settings that would normally go in the tomcat or jetty elements within the container-config should just go directly into the web-app element of the deployment plan.

If the web deployment plan uses one of those namespaces, it will only be possible to deploy it in a Geronimo configuration containing the correct web container.

[Tip]Tip

Since both Tomcat and Jetty are supported in Geronimo, it's strongly recommended that the portable deployment plan format be used (instead of the container-specific plans described here). The main reason to use these plan formats is to support a Geronimo stack contaning both Tomcat and Jetty, though as there is no Geronimo distribution that ships that way, you'd have to create such a stack yourself to begin with.

Example 11.6. Tomcat-only and Jetty-only Deployment Plans

This example shows a simple web app configuration, with a virtual host setting, as it would appear in a portable, Tomcat-only, and Jetty-only plan. Note that the virtual host settings normally appear in the container-config section of the plan, but in the non-portable cases, appear directly within the web-app element.

Portable geronimo-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.0"
    configId="MyConfigName">
  <context-root>/MyWebApp</context-root>
  <container-config>
    <tomcat 
xmlns="http://geronimo.apache.org/xml/ns/web/tomcat/config-1.0">
      <host>virtual.company.com</host>
      <!-- Note that a Tomcat HostGBean must be deployed in
           Geronimo that corresponds to this host name. -->
    </tomcat>
    <jetty
xmlns="http://geronimo.apache.org/xml/ns/web/jetty/config-1.0">
      <virtual-host>virtual.company.com</virtual-host>
    </jetty>
  </container-config>
</web-app>

Jetty-Only geronimo-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/jetty-1.0"
    configId="MyConfigName">
  <context-root>/MyWebApp</context-root>
  <virtual-host>virtual.company.com</virtual-host>
</web-app>

Tomcat-Only geronimo-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/tomcat-1.0"
    configId="MyConfigName">
  <context-root>/MyWebApp</context-root>
  <host>virtual.company.com</host>
  <gbean name="MyVirtualHost"
         class="org.apache.geronimo.tomcat.HostGBean">
  <attribute name="className">
    org.apache.catalina.core.StandardHost
  </attribute>
  <attribute name="initParams">
    name=virtual.company.com
    appBase=
    workDir=work
  </attribute>
</gbean>
</web-app>