为什么我在Maven Dynamic Web模块中收到此404错误



我是全新到泽西岛/jax-rs/Restful Web Services/等。而且我的泽西原型遇到了困难,称为jersey-quickstart-webapp。我试图将其与Eclipse,Maven和Tomcat V7或V8一起使用(我尝试了两者)。

首先,我有一个JSP错误:
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path. 我解决了有关错误的问题。显然,Maven并没有将我的项目视为动态的Web应用程序。

然后我得到了警告:
Build path specifies execution environment JavaSE-1.7. There are no JREs installed in the workspace that are strictly compatible with this environment。我解决了第二个问题,并在此问题上解决了另一个问题。我最初使用Javase-1.8。

最后,我有最后一个错误:
Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result.再次,我对此事进行了检查,并将关联的原始类Path从潜在的发布/导出依赖项组中排除。

但是,我的项目仍然有404个,我无法弄清楚原因。我正在为此项目使用pom.xml文件。我关注的教程告诉我,这里使用的正确URL是http://localhost:8080/messenger/

这不是答案(将被删除)

编辑:变成社区Wiki。这不是解决方案。

尝试将此码头插件添加到该应用中。pom.xml文件中的<build><plugins>内部

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.2.6.v20141205</version>
</plugin>

然后右键单击项目,maven-&gt;建造;在目标类型jetty:run的对话框中,并尝试运行构建。这应该启动嵌入式码头服务器。控制台说" Jetty Server启动"后,您应该能够访问http://localhost:8080/webapi/myresource。只想查看应用程序是否有问题。

快速临时解决方案:

更改 WebApi to Webresources 在URL中:http://localhost:8080/webapi/myResource

永久解决方案:

更改文件web.xml

<url-pattern>/webresources/*</url-pattern>

to

<url-pattern>/webapi/*</url-pattern>

相关内容