Java is a very productive development environment if you choose and combine the right tools and patterns.
Jease is the result of my personal quest bringing tools and patterns together which make the life of a web-developer as simple as it can be.
The following howto uses Jease as an example, but it is applicable for every web-application which needs to generate pretty urls.
Jease tries really hard to make pretty urls simple. In order to achieve this goal, Jease relies on two concepts:
This works like a charm for one Jease-Instance. But what do you do if you want to run several independent Jease-instances from one physical server?
The simple approach would be to install and run several servlet containers on different ports and hide them via a proxy (like Apache)... but that's usually a waste of ressources.
A better approach is to deploy several instances within the same servlet container... but stop: we already deployed one Jease-instance as ROOT-application in our webapps-folder, so no second instance can take this special position.
But if we want to run independent sites for different domains, we can make use of a concept called "Virtual Hosting". A servlet contaienr is able to serve different applications depending on the requested domain.
... <!-- This entry is already contained in server.xml --> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" /> <!-- This entry adds a virtual host for yourdomain.org --> <Host name="yourdomain.org" appBase="sites/yourdomain.org" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" /> ...
<Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/</Set> <Set name="war"> <SystemProperty name="jetty.home"/>/sites/yourdomain.org/ROOT.war </Set> <Set name="virtualHosts"> <Array type="java.lang.String"> <Item>www.yourdomain.org</Item> </Array> </Set> </Configure>
If you're running Apache in front of your servlet container, you'll need to configure Apache as proxy server for your servlet container as follows:
<Proxy http://www.yourdomain.org:8080/> Order Allow,Deny Allow from all </Proxy> <VirtualHost *:80> ServerName yourdomain.org ServerAlias www.yourdomain.org ProxyPass / http://www.yourdomain.org:8080/ ProxyPassReverse / http://www.yourdomain.org:8080/ </VirtualHost>
This way you can easily add additional sites as well. That's easy, isn't it?
Last modified on 2012-04-23 by Maik Jablonski