Differences
This shows you the differences between two versions of the page.
osgi_web_application [2014/03/18 21:39] |
osgi_web_application [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== OSGi Web Application ====== | ||
+ | OSGi has support for web applications included for a long time in form of Java Servlet support. | ||
+ | ===== Maven ===== | ||
+ | The maven-bundle-plugin does most of the work for getting the manifest right. | ||
+ | |||
+ | <sxh xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <!-- Need to use this plugin to build war files --> | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | The project specific manifest entries are extracted into an extra properties file: | ||
+ | |||
+ | <sxh title: | ||
+ | Bundle-ClassPath: | ||
+ | Web-ContextPath: | ||
+ | </ | ||
+ | |||
+ | It is important to add the root of the WAR file to the bundle classpath. | ||
+ | |||
+ | ===== Servlet ===== | ||
+ | An extremely simple Servlet: | ||
+ | |||
+ | <sxh java> | ||
+ | import java.io.IOException; | ||
+ | import java.io.PrintWriter; | ||
+ | |||
+ | import javax.servlet.ServletException; | ||
+ | import javax.servlet.annotation.WebServlet; | ||
+ | import javax.servlet.http.HttpServlet; | ||
+ | import javax.servlet.http.HttpServletRequest; | ||
+ | import javax.servlet.http.HttpServletResponse; | ||
+ | |||
+ | @WebServlet(displayName=" | ||
+ | public class SimpleServlet extends HttpServlet { | ||
+ | |||
+ | @Override | ||
+ | protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
+ | throws ServletException, | ||
+ | PrintWriter writer = response.getWriter(); | ||
+ | writer.println(" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | No '' | ||
+ | |||
+ | ===== Apache Karaf ===== | ||
+ | For this example to work in Apache Karaf only the '' | ||
+ | |||
+ | feature: | ||
+ | |||
+ | {{tag> |