Jetty의 Distribution Version은 8.1.11.
Jetty Download : http://download.eclipse.org/jetty/
Jersey Version : 1.8
Jersey Download : http://repo1.maven.org/maven2/com/sun/jersey/jersey-bundle/
<Main.java>
public class Main {/*** @param args* @throws Exception*/public static void main(String[] args) throws Exception {//Jetty Server Start for RESTful ServiceJettyServer jettyServer = new JettyServer();if (!jettyServer.isStarted())jettyServer.start();}}
<JettyServer.java>
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;import com.sun.jersey.api.core.PackagesResourceConfig;import com.sun.jersey.spi.container.servlet.ServletContainer;public class JettyServer {private Server server;public JettyServer() {this(8080);}public JettyServer(Integer port) {server = new Server(port);server.setStopAtShutdown(true);server.setSendServerVersion(true);ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);handler.setContextPath("/");handler.addServlet(new ServletHolder(new ServletContainer(new PackagesResourceConfig("restful_resource_package"))), "/");server.setHandler(handler);}public void setHandler(ContextHandlerCollection contexts) {server.setHandler(contexts);}public void start() throws Exception {server.start();}public void stop() throws Exception {server.stop();server.join();}public boolean isStarted() {return server.isStarted();}public boolean isStopped() {return server.isStopped();}}
한가지 유의할 사항은, Jersey Annotation을 사용하여 작성할 모든 Resource는 restful_resource_package에 작성되어야 한다는 것이다.
댓글을 달아 주세요
댓글 RSS 주소 : http://www.yongbi.net/rss/comment/568