Skip to content

Instantly share code, notes, and snippets.

@spullara
Created March 27, 2013 04:13
Show Gist options
  • Save spullara/5251586 to your computer and use it in GitHub Desktop.
Save spullara/5251586 to your computer and use it in GitHub Desktop.
Initialize JAX-RS in Jetty
Server server = new Server(config.getPort());
final ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
ServletHolder jaxrs = new ServletHolder(ServletContainer.class);
jaxrs.setInitParameter("javax.ws.rs.Application", applicationClassName);
final ServletContextHandler mainHandler = new ServletContextHandler(contexts, "/", true, false);
mainHandler.addServlet(jaxrs, "/*");
@cowtowncoder
Copy link

Quick question on imports: which ones are from Jetty vs JAX-RS (Jersey?)

@spullara
Copy link
Author

import com.sun.jersey.spi.container.servlet.ServletContainer;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment