Why am I receiving this 404 Error in my Maven Dynamic Web Module?

时间:2015-05-12 22:23:25

标签: java eclipse maven tomcat jersey

I'm brand-new to Jersey/JAX-RS/RESTful Web Services/etc. and I'm having difficulty with a Jersey archetype called User.all.to_a. I'm attempting to use it with Eclipse, Maven, and Tomcat v7 or v8 (I've tried both).

First I got a JSP error:
jersey-quickstart-webapp I resolved that error with this SO question regarding the error. Apparently Maven wasn't treating my project as a Dynamic Web Application.

Then I got a warning about:
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path.. I resolved the second issue with another SO question on the matter. I was originally using JavaSE-1.8.

Finally, I had one last error:
Build path specifies execution environment JavaSE-1.7. There are no JREs installed in the workspace that are strictly compatible with this environmentAgain, I checked SO on the matter and excluded the associated raw classpath entry from the set of potential publish/export dependencies.

However, I am still given a 404 on my project and I cannot figure out why. I'm using a pom.xml file for this project. The tutorial I'm following is telling me that the correct URL to be using here is Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result..

2 个答案:

答案 0 :(得分:1)

这不是答案(将被删除)

修改:转变为社区维基。它不是解决方案。

尝试将此jetty插件添加到应用程序中。在<build><plugins>文件

中的pom.xml
<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.2.6.v20141205</version>
</plugin>

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

答案 1 :(得分:0)

快速临时解决方案:

webapi 更改为网址中的网络资源http://localhost:8080/webapi/myresource

永久解决方案:

更改文件web.xml

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

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