I want to create and deploy a web service to OSGi container. For example, publish the service to the address:
http://localhost:8080/testservice.
If you use bndtools, create a Declarative Services project and add this annotation to your servlet:
@Component(provide = Servlet.class, properties = {"alias=/hello"})
public class HelloWorldServlet extends HttpServlet { ... }
Then create a bnd run descriptor with 'Apache Felix 4 with Web Console and Gogo', just add the Apache Felix Http whiteboard bundle and you're good to go. You can find your servlet at http://localhost:8080/hello
How it works. The @Component annotation makes your class a service (a Servlet service in this case due to the provide attribute). This is registered with the service property 'alias'. The Apache Felix Http Whiteboard bundle picks up these services and registers them as servlets. I do not think it can get any simpler than this.