package cz.hsrs.main;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class JettyServer {

    private static final int DEFAULT_PORT = 8080;
    private static final String DEFAULT_PREFIX = "/DBService";

    public Server server;

    public void start() throws Exception {
        server = new Server(DEFAULT_PORT);

        WebAppContext context = new WebAppContext();
        context.setServer(server);
        context.setContextPath(DEFAULT_PREFIX);
//        context.setWar("src/main/webapp");
        context.setResourceBase("src/main/webapp");
        context.setDefaultsDescriptor("src/main/webapp/WEB-INF/web.xml");
        server.setHandler(context);

        try {
            server.start();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
            stop();
        }
    }
    public void stop() throws Exception {
        if (server != null) {
            server.stop();
        }
    }
}
