Web applications

Installing war support

The following steps will install the "war" feature (support for deploying WAR files with Servlet and JSPs into a Jetty server) into your Karaf instance.

  1. List the available features -

    karaf@root> features:list 
     State        Name
    . . .
    [uninstalled] [2.2.0] obr        karaf-2.2.0
    [uninstalled] [2.2.0] config     karaf-2.2.0
    [uninstalled] [2.2.0] http       karaf-2.2.0
    [uninstalled] [2.2.0] war        karaf-2.2.0
    [uninstalled] [2.2.0] webconsole karaf-2.2.0
    [installed  ] [2.2.0] ssh        karaf-2.2.0
    . . .
    
  2. Install the war feature (and the sub-features it requires) -

    karaf@root> features:install war 
    

    Note: you can use the -v or --verbose to see exactly what Karaf does

    karaf@root> features:install -v war
    Installing feature war 2.1.99-SNAPSHOT
    Installing feature http 2.1.99-SNAPSHOT
    Installing feature jetty 7.1.6.v20100715
    Installing bundle mvn:org.apache.geronimo.specs/geronimo-servlet_2.5_spec/1.1.2
    Found installed bundle: org.apache.servicemix.bundles.asm [10]
    Installing bundle mvn:org.eclipse.jetty/jetty-util/7.1.6.v20100715
    Installing bundle mvn:org.eclipse.jetty/jetty-io/7.1.6.v20100715
    Installing bundle mvn:org.eclipse.jetty/jetty-http/7.1.6.v20100715
    Installing bundle mvn:org.eclipse.jetty/jetty-continuation/7.1.6.v20100715
    Installing bundle mvn:org.eclipse.jetty/jetty-server/7.1.6.v20100715
    Installing bundle mvn:org.eclipse.jetty/jetty-security/7.1.6.v20100715
    Installing bundle mvn:org.eclipse.jetty/jetty-servlet/7.1.6.v20100715
    Installing bundle mvn:org.eclipse.jetty/jetty-xml/7.1.6.v20100715
    Checking configuration file mvn:org.apache.karaf/apache-karaf/2.1.99-SNAPSHOT/xml/jettyconfig
    Installing bundle mvn:org.ops4j.pax.web/pax-web-api/0.8.2-SNAPSHOT
    Installing bundle mvn:org.ops4j.pax.web/pax-web-spi/0.8.2-SNAPSHOT
    Installing bundle mvn:org.ops4j.pax.web/pax-web-runtime/0.8.2-SNAPSHOT
    Installing bundle mvn:org.ops4j.pax.web/pax-web-jetty/0.8.2-SNAPSHOT
    Installing bundle mvn:org.ops4j.pax.web/pax-web-jsp/0.8.2-SNAPSHOT
    Installing bundle mvn:org.ops4j.pax.web/pax-web-extender-war/0.8.2-SNAPSHOT
    Installing bundle mvn:org.ops4j.pax.web/pax-web-extender-whiteboard/0.8.2-SNAPSHOT
    Installing bundle mvn:org.ops4j.pax.web/pax-web-deployer/0.8.2-SNAPSHOT
    Installing bundle mvn:org.ops4j.pax.url/pax-url-war/1.2.4
    
  3. Verify the features were installed

    servicemix> features/list
     State        Name
    . . .
    [installed ] [2.2.0] http karaf-2.2.0
    [installed ] [2.2.0] war  karaf-2.2.0
    . . .
    
  4. Verify the installed bundles were started

    karaf@root> osgi:list 
    START LEVEL 100
       ID   State         Level  Name
    . . .
    [ 32] [Active ] [ ] [ 60] geronimo-servlet_2.5_spec (1.1.2) 
    [ 33] [Active ] [ ] [ 60] Apache ServiceMix :: Bundles :: jetty (6.1.22.2) 
    [ 34] [Active ] [ ] [ 60] OPS4J Pax Web - API (1.0.0)
    [ 35] [Active ] [ ] [ 60] OPS4J Pax Web - Service SPI (1.0.0)
    [ 36] [Active ] [ ] [ 60] OPS4J Pax Web - Runtime (1.0.0)
    [ 37] [Active ] [ ] [ 60] OPS4J Pax Web - Jetty (1.0.0)
    [ 38] [Active ] [ ] [ 60] OPS4J Pax Web - Jsp Support (1.0.0)
    [ 39] [Active ] [ ] [ 60] OPS4J Pax Web - Extender - WAR (1.0.0)
    [ 40] [Active ] [ ] [ 60] OPS4J Pax Web - Extender - Whiteboard (1.0.0)
    [ 42] [Active ] [ ] [ 60] OPS4J Pax Web - FileInstall Deployer (1.0.0)
    [ 41] [Active ] [ ] [ 60] OPS4J Pax Url - war:, war-i: (1.2.4)
    . . .
    
  5. The Jetty server should now be listening on http://localhost:8181/, but with no published applications available.

    HTTP ERROR: 404
    NOT_FOUND
    RequestURI=/
    Powered by jetty://
    

Deploying a WAR to the installed web feature

The following steps will describe how to install a simple WAR file (with JSPs or Servlets) to the just installed web feature.

  1. To deploy a WAR (JSP or Servlet) to Jetty, update its MANIFEST.MF to include the required OSGi headers as described here -

    http://team.ops4j.org/wiki/display/ops4j/Pax+Web+Extender+-+War+-+OSGi-fy

  2. Copy the updated WAR (archive or extracted files) to the deploy directory.

If you want to deploy a sample web application into Karaf, you could use the following command:

karaf@root> osgi:install -s webbundle:http://tomcat.apache.org/tomcat-5.5-doc/appdev/sample/sample.war?Bundle-SymbolicName=tomcat-sample&Webapp-Context=/sample

Then open your web browser and point to http://localhost:8181/sample/index.html.