嵌入式Jetty中的Web应用程序获取错误404未找到

Int*_*ata 8 java embedded-jetty http-status-code-404

我想部署带有嵌入式Jetty服务器的Java Netbeans Webapp; 服务器本身工作,但我总是得到以下错误:

在此输入图像描述

我在网上搜索了大量的例子,配置并重新配置了我的web.xml; 虽然我的配置似乎很好,但我无法让它工作.

我应该指出,当我使用内置的Glassfish服务器从whithin Netbeans运行应用程序时,它工作正常,这告诉我web.xml可能配置得很好.

有人能帮忙吗?

我的代码如下.

PS我知道它已被问过,但这些例子对我来说也不起作用.

项目结构:

在此输入图像描述

WebContext设置:

import org.eclipse.jetty.webapp.WebAppContext;

public class AppContextBuilder {

    private WebAppContext webAppContext;

    public WebAppContext buildWebAppContext() {
        webAppContext = new WebAppContext();
        webAppContext.setDescriptor(webAppContext + "/WEB-INF/web.xml");
        webAppContext.setResourceBase("src/main/webapp");
        webAppContext.setContextPath("/Holmes");

        return webAppContext;
    }
}
Run Code Online (Sandbox Code Playgroud)

JettyServer.java:

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;

public class JettyServer {

    private Server server;

    public JettyServer() {
        this(8585);
    }

    public JettyServer(Integer runningPort) {
        server = new Server(runningPort);
    }

    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();
    }
}
Run Code Online (Sandbox Code Playgroud)

Deploy.java(主方法):

import org.apache.log4j.Logger;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;

/**
 *
 * @author Motty Waldner <motty@timeworksny.com>
 */

public class Deploy {

    private final static Logger log = Logger.getLogger(Deploy.class);

    static JettyServer jettyServer = new JettyServer();

    public static void main(String[] args) throws Exception {
        // add hook to stop server upon service termination
        // (service calls System.exit(0) upon termination,
        // so it should work under normal circumstances)
        addShutdownHook();

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        Handler[] handlers = new Handler[]{new AppContextBuilder().buildWebAppContext().getHandler()};
        contexts.setHandlers(handlers);

        jettyServer = new JettyServer();

        try {
            jettyServer.start();
        } catch (Exception e) {
            log.error("Error Starting Jetty Server", e);
        }
    }

    private static void addShutdownHook() {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                try {
                    jettyServer.stop();
                    log.info("Shutdown Hook is running: Jetty Server instance being stopped.");
                } catch (Exception e) {
                    log.error("error", e);
                }

                log.info("Application Terminating ...");
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

web.xml中:

    <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Test App</display-name>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name> struts2 </filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <session-config>  
        <session-timeout>120</session-timeout>  
    </session-config>

    <servlet-mapping>
        <servlet-name>StrutsController</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

</web-app>
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助!

Joa*_*elt 0

改变

Handler[] handlers = new Handler[]{new AppContextBuilder().buildWebAppContext().getHandler()};
Run Code Online (Sandbox Code Playgroud)

Handler[] handlers = new Handler[]{new AppContextBuilder().buildWebAppContext()};
Run Code Online (Sandbox Code Playgroud)