Skip to main content Skip to complementary content

Web Applications

Karaf provides an ability to deploying WAR-based web applications within the Jetty server contained in the Karaf instance.

Installing WAR support

About this task

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.

Procedure

  1. List the available features:
    karaf@trun> feature:list 
    State        Name
    ...
    [uninstalled] [2.2.9] obr        karaf-2.2.9
    [uninstalled] [2.2.9] config     karaf-2.2.9
    [uninstalled] [2.2.9] http       karaf-2.2.9
    [uninstalled] [2.2.9] war        karaf-2.2.9
    [uninstalled] [2.2.9] webconsole karaf-2.2.9
    [installed  ] [2.2.9] ssh        karaf-2.2.9
    ...
  2. Install the war feature (and the sub-features it requires):
    karaf@trun> feature:install war
    Note: you can use the -v or --verbose switch to see exactly what Karaf does, and this will show the war, http, and jetty features being installed, along with dependent bundles.
  3. Check that the features were installed:
    karaf@trun> feature:list
    State        Name
    ...
    [installed ] [2.2.9] http karaf-2.2.9
    [installed ] [2.2.9] war  karaf-2.2.9
    ...
  4. Check that the installed bundles were started:
    karaf@trun> 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)
    ...
    Note: the version numbers of the packages may be different in your installation.
  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

About this task

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

Procedure

  1. To deploy a WAR (JSP or Servlet) to Jetty, update its MANIFEST.MF to include the required OSGi headers as described here: http://ops4j.github.io/pax/web/6.x/User-Guide.html#war-extender
  2. Copy the updated WAR (archive or extracted files) to the deploy directory.

Results

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

karaf@trun> bundle: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.

Masking the Jetty version

To secure the Jetty server from malicious attacks, it is necessary to hide its version information.

Procedure

  1. Go to the etc directory and open the jetty.xml file to edit it.
  2. For the class org.eclipse.jetty.server.Server, add:
    <Set name="sendServerVersion">false</Set>

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!