This example show how to register a servlet in the Karaf HTTP Service.
It uses different approaches:
@WebServlet
annotation using the Karaf annotation scanner@WebServlet
Servlet 3.0 annotation to register.The build uses Apache Maven. Simply use:
mvn clean install
On a running Karaf instance, you register the example features repository with:
karaf@root()> feature:repo-add mvn:org.apache.karaf.examples/karaf-servlet-example-features/LATEST/xml
The karaf-servlet-example-annotation
feature installs the required features (HTTP service) and register the servlet using Servlet 3.0 annotation:
karaf@root()> feature:install karaf-servlet-example-annotation
The karaf-servlet-example-registration
feature installs the required features (HTTP service) and register the servlet by hand in the Karaf HTTP service:
karaf@root()> feature:install karaf-servlet-example-registration
The karaf-servlet-example-blueprint
feature installs the required features (HTTP service & blueprint) and register the servlet using a Servlet service:
karaf@root()> feature:install karaf-servlet-example-blueprint
The karaf-servlet-example-scr
feature installs the required features (HTTP service & SCR) and register the servlet using a Servlet service:
karaf@root()> feature:install karaf-servlet-example-scr
Whatever feature you use, you can access the servlet on the following URL: