How to add multiple EndPoint Jax-rs inside a jetty server.
I am trying to create services using jetty.
My first problem is that I can't add more than one EndPoint to the server at a time.
When I add two, the first is overwriting the second.
public static void main(String[] args) throws Exception {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
Server jettyServer = new Server(8080);
jettyServer.setHandler(context);
String[] arrayOfResources = new String[3];
arrayOfResources[0] = EmployeeResource.class.getCanonicalName();
arrayOfResources[1] = HelloWorld.class.getCanonicalName();
arrayOfResources[2] = FilterRest.class.getCanonicalName();
ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,"/*");
jerseyServlet.setInitOrder(0);
jerseyServlet.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
jerseyServlet.setInitParameter("com.sun.jersey.config.property.packages", "resources");
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames",
EmployeeResource.class.getCanonicalName());
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames",
HelloWorld.class.getCanonicalName());
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames",
FilterRest.class.getCanonicalName());
try {
jettyServer.start();
jettyServer.join();
} catch (Exception e) {
e.printStackTrace();
} finally {
jettyServer.destroy();
}
}