1

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();
        }
    }

  • 1
    You'll find some valuable information (that should help you solve your problem) in [this post](https://stackoverflow.com/a/45627178/2587435). Hint: you're using the wrong property name. The one you are using is from Jersey 1.x. You are using 2.x. Different. – Paul Samsotha Aug 10 '19 at 23:24

0 Answers0