Created
February 16, 2015 13:40
-
-
Save craigleonard/205ba0986933a47e9902 to your computer and use it in GitHub Desktop.
Embedded Jetty hosting a Jetty 2 Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.eclipse.jetty.server.Server; | |
import org.eclipse.jetty.servlet.ServletContextHandler; | |
import org.eclipse.jetty.servlet.ServletHolder; | |
import org.glassfish.jersey.server.ResourceConfig; | |
import org.glassfish.jersey.servlet.ServletContainer; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
public class Main { | |
@Path("/api") | |
public static class HelloResource { | |
@GET | |
public String hello() { | |
return "Hello Jetty"; | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
ResourceConfig resourceConfig = new ResourceConfig(); | |
resourceConfig.register(new HelloResource()); | |
ServletContextHandler contextHandler = new ServletContextHandler(); | |
ServletHolder servletHolder = new ServletHolder(new ServletContainer(resourceConfig)); | |
contextHandler.addServlet(servletHolder, "/*"); | |
Server server = new Server(8080); | |
server.setHandler(contextHandler); | |
server.start(); | |
server.join(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment