Jetty Embedded Server can't find jsp and Servlets

时间:2016-08-31 18:42:03

标签: java servlets jetty

i have write a Java Swing Application with embedded jetty server. When i start this project in eclipse its all fine. But when i build a executeable jar the jetty server starts but he cant find any servlet.

My folderstructure

folderstructure

My ServerHandler class

public class ServerHandler {

private Logger logger = LoggerFactory.getLogger(ServerHandler.class);

private static ServerHandler SINGLETON;

private Server server;

private PropertiesUtil propertiesUtil = PropertiesUtil.getInstance();

private ServerHandler() {

}

public static ServerHandler getInstance() {
    if (SINGLETON == null) {
        SINGLETON = new ServerHandler();
    }
    return SINGLETON;
}

public void start() throws Exception {
    this.server = new Server(propertiesUtil.getInt("server.port"));
    WebAppContext ctx = new WebAppContext();
    ctx.setResourceBase("./webapp");
    String contextPath = propertiesUtil.getString("server.contextpath");
    ctx.setContextPath("/" + contextPath);
    System.out.println(contextPath);
    ctx.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*jstl.*\\.jar$");
    org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList
            .setServerDefault(server);
    classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration",
            "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
            "org.eclipse.jetty.annotations.AnnotationConfiguration");
    this.server.setHandler(ctx);
    this.server.start();
    logger.info("Server wurde {}", "gestartet");
}

public void stop() throws Exception {
    this.server.stop();
}

public boolean isStarted() {
    return this.server != null && this.server.isStarted();
}

public void restart() throws Exception {
    stop();
    start();
}

}

0 个答案:

没有答案