|Home > Documentation > Apache Geronimo v1.1 - User's Guide > Sample applications > Exposing Web applications on distinct ports|
|EJB sample application||Sample applications||Geronimo Tomcat Context Level Clustering - Sample Application|
You may wish to run different web applications on different ports. For example, you might want an admin application on a different port than a production application.
This example also demonstrates how to start listening on the ports after the web applications are fully deployed and ready to be used.
In non-geronimo tomcat, you can do this by including two or more server definitions in your server.xml file, and including the applications in the server elements. It's possible to set up essentially the same structure in geronimo.
Here's the sample app:
If you unpack it you can deploy it inplace with something like
java -jar bin/deployer.jar deploy --inPlace appPerPort.ear
(Assuming you have logged in to the deployer previously)
Here's the plan, with some explanation. The first thing that happens is that the gbeans in the ear scope start; this starts 2 tomcat servers but no connectors for them.
Then the three web apps start in order. The first two are actual web apps with content. Note that each has a web-container gbean-link to the appropriate web container that just started.
The third web app has the connector gbeans for the web containers we started. Note that the web apps are modules as well as the ear itself, and that web modules start in the same order as they are listed in application.xml. Recall also that in order for a module to start, all its gbeans must start completely. Therefore we have first the tomcat containers starting, then the web apps deployed onto different tomcat containers, and finally once the web apps are completely started, the connectors that open listeners on the two different ports.
Putting the connector gbeans into an otherwise empty web app succeeds in delaying opening the ports until after the applications are ready, but is not exactly elegant. If you are willing to have more than one module, you can put the connector gbeans into a service plan and list the ear as a dependency to get the same effect.
Jetty web apps have the same ability to specify which jetty container should be used, however I don't have a sample plan to demonstrate that it works.
There may be a simpler way to limit which ports an app in a jetty web container is available on, in which case for jetty one would not need 2 jetty containers. This requires further investigation.