RSS feed
Home | Notes on Pocket Internet Explorer (Windows Mobile 2003 SE) >>

Jetty 6.1.6 + Apache 2.2 + Web application

As a test for the new blogging software, I decided to write a short note describing a fast way to configure a Jetty server for your web application.

Jetty supports the use of a front-end HTTP server such as Apache as a front-end server for e.g. serving static files. Jetty is fast, small and full-featured Java-based HTTP server, especially useful for deploying Java-based web applications.

Here's a short walkthrough for configuring a Jetty with a Apache 2.2 front-end using AJP13. For more information see the original  guide on Jetty website.

Prerequisites:
  • Apache 2.2
  • Jetty 6.1.x (downloadable here (http://dist.codehaus.org/jetty/))
  • Your webapplication (later MyWebApp)
  • Java 1.6
JETTY_DIR = the Jetty installation directory
HTTPD_CONFIG_DIR = Apache configuration dir for external config files, e.g. /etc/httpd/conf.d

Steps:

- First install the JDK and Jetty to your preferred locations.
- Remove the testing stuff included in the distribution package (Optional):

rm contexts/test.xml
rm contexts/test-jndi.xml
rm contexts/javadoc.xml
rm -rf contexts/test-jndi.d
rm -rf contexts/test.d
rm -rf webapps/*

- Edit the jetty.xml configuration file in JETTY_DIR/etc/jetty.xml
  • Replace the following:

   <Call name="addConnector">
      <Arg>
          <New class="org.mortbay.jetty.nio.SelectChannelConnector">
            <Set name="host"><SystemProperty name="jetty.host" /></Set>
            <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
            <Set name="maxIdleTime">30000</Set>
            <Set name="Acceptors">2</Set>
            <Set name="statsOn">false</Set>
            <Set name="confidentialPort">8443</Set>
            <Set name="lowResourcesConnections">5000</Set>
            <Set name="lowResourcesMaxIdleTime">5000</Set>
          </New>
      </Arg>
    </Call>

  • With the following:

<Call name="addConnector">
      <Arg>
        <New class="org.mortbay.jetty.ajp.Ajp13SocketConnector">
          <Set name="host">127.0.0.1</Set> 
          <Set name="port">8009</Set>     
        </New>                    
      </Arg>                             
  </Call>


- Next, copy the war file to your preferred location, e.g. /opt/mywebapp/MyWebApp.war

- Then create the a context file for Jetty in JETTY_DIR/contexts, named MyWebApp.xml
    - This enables, for example, Jetty hot-deploy support. If this is not needed you could just extract the WAR to JETTY_DIR/webapps
  • Contents:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://jetty.mortbay.org/configure.dtd">

<Configure class="org.mortbay.jetty.webapp.WebAppContext">

      <Set name="contextPath">/TarpChecking</Set>
      <Set name="war">/FullPathTo/MyWebApp.war</Set>
      <Set name="extractWAR">true</Set>
      <Set name="copyWebDir">false</Set>
      <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
</Configure>
 

- Start Jetty with a designated init script (available in Jetty RPM distribution), or by running java -jar start.jar etc/jetty.xml in JETTY_DIR.

- Now, the configuration of Apache, which is very straightforward:
- Add the following file to HTTPD_CONFIG_DIR: mod_proxy_ajp.conf
  • Contents (if no clustering is used... for clustering example, see the original guide.

LoadModule proxy_ajp_module /your_apache2_lib_dir/mod_proxy_ajp.so
ProxyPass /MyWebApp ajp://127.0.0.1:8009/MyWebApp
ProxyPreserveHost On

Note: The Apache 2 lib directory location depends on the Linux distribution / Apache build configuration used. For example, the default  path for 64-bit OpenSUSE is  /usr/lib64/apache2 and for CentOS 5 /usr/lib/httpd/modules

- Reboot Apache process, and your application should be accessible in http://yourserver/MyWebApp/

Disclaimer: This is not an official guide for installing Jetty. For official guides please refer to Jetty website.



Re: Jetty 6.1.6 + Apache 2.2 + Web application

Hi Thanks for info, could you please tell me if I can use continuation feature with apache and jetty combination? Please bare with me I am newbie for Jetty and continuation and I want to use apache for static contents. Thanks in advance.

Add a comment Send a TrackBack