`

Start Jersey rest api with embedded Jetty

 
阅读更多
引用
This is an sample to start Jersey rest api with embedded Jetty, embedded jetty is easy for packaging in linux


public class JerseyStart
{

    public static void main(final String[] args) throws IOException
    {
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
        context.setContextPath("/");

        Server jettyServer = new Server(9999);
        jettyServer.setHandler(context);

        ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
        jerseyServlet.setInitOrder(0);

        // Tells the Jersey Servlet which REST service/class to load.
        jerseyServlet
            .setInitParameter("com.sun.jersey.config.property.packages", "com.*.*.*.service");

        try
        {
            jettyServer.start();
            jettyServer.join();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            jettyServer.destroy();
        }
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics