404 Not Found Error in a simple Jetty/Maven Hello World webapp

99封情书 提交于 2019-12-05 03:49:54

The tutorial gives the incorrect url - your app context is still "/", so the urls are http://localhost:8080 and http://localhost:8080/hello for the static and dynamic content, respectively.

The maven jetty plugin documentation does claim that the default context will be named the same as the artifactId in the pom.xml, but that doesn't seem to be working here.

I ran into the same issue and what worked for me was accessing the app like: http://localhost:8080/hello/index.jsp or http://localhost:8080/hello/index.html, whatever you're using html or js pages.

I think adding configuration to the jetty plugin definition in your pom should change the contextpath to hello-world:

        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${jettyVersion}</version>
            <configuration>
                <webApp>
                    <contextPath>/hello-world</contextPath>
                </webApp>
            </configuration>
        </plugin>

This is based on jetty version 9. See http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin for the configuration options.

I had the same problem with a basic configuration.

I wanted to redirect with Spring 3 MVC an error page with this configuration (in web.xml)

<error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/views/error.html</location>
</error-page>

I solve it by changing extension of error.html to error.jsp.

Evgeniy Kochetkov

I think you don't run mvn package task before mvn jetty:run that is why jetty doesn't see any sources. Just run mvn package first.

Your servlet mapping is incorrect or insufficient.

<url-pattern>/hello/*</url-pattern> // does not respond to "/hello"

You need to add a mapping for the URL pattern "/hello"

<url-pattern>/hello</url-pattern>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!