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

时间:2022-05-25 19:34:26

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

我是Jersey / JAX-RS / RESTful Web Services /等全新的。而我在使用名为jersey-quickstart-webapp的Jersey原型时遇到了困难。我正在尝试将它与Eclipse,Maven和Tomcat v7或v8一起使用(我已尝试过两者)。

First I got a JSP error:
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path. I resolved that error with this SO question regarding the error. Apparently Maven wasn't treating my project as a Dynamic Web Application.

首先我遇到了一个JSP错误:在Java Build Path中找不到超类“javax.servlet.http.HttpServlet”。我通过这个关于错误的SO问题解决了这个错误。显然,Maven没有将我的项目视为动态Web应用程序。

Then I got a warning about:
Build path specifies execution environment JavaSE-1.7. There are no JREs installed in the workspace that are strictly compatible with this environment. I resolved the second issue with another SO question on the matter. I was originally using JavaSE-1.8.

然后我收到一个警告:Build path指定执行环境JavaSE-1.7。工作区中没有安装与此环境严格兼容的JRE。关于此事,我在另一个SO问题上解决了第二个问题。我最初使用的是JavaSE-1.8。

Finally, I had one last error:
Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result.Again, I checked SO on the matter and excluded the associated raw classpath entry from the set of potential publish/export dependencies.

最后,我有一个最后一个错误:类路径条目org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER将不会被导出或发布。可能会导致运行时ClassNotFoundExceptions.Again,我检查了SO,并从潜在的发布/导出依赖项集中排除了关联的原始类路径条目。

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 http://localhost:8080/messenger/.

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

2 个解决方案

#1


This is not an answer (will be deleted)

Edit: Turned into community wiki. It's not a solution.

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

Try and add this jetty plugin to the app. Inside the <build><plugins> in the pom.xml file

尝试将此jetty插件添加到应用程序。在pom.xml文件中的

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

Then Right click on project, Maven -> Build; in the dialog on the goals type jetty:run and try to run the build. This should start an embedded jetty server. Once the console says "Jetty Server started", you should be able to access http://localhost:8080/webapi/myresource. Just want to see if it is a problem with the app.

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

#2


Fast Temporary solution:

快速临时解决方案:

Change webapi to webresources in the url: http://localhost:8080/webapi/myresource

将webapi更改为url中的webresources:http:// localhost:8080 / webapi / myresource

Permanent solution:

Change the file web.xml

更改文件web.xml

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

to

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

#1


This is not an answer (will be deleted)

Edit: Turned into community wiki. It's not a solution.

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

Try and add this jetty plugin to the app. Inside the <build><plugins> in the pom.xml file

尝试将此jetty插件添加到应用程序。在pom.xml文件中的

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

Then Right click on project, Maven -> Build; in the dialog on the goals type jetty:run and try to run the build. This should start an embedded jetty server. Once the console says "Jetty Server started", you should be able to access http://localhost:8080/webapi/myresource. Just want to see if it is a problem with the app.

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

#2


Fast Temporary solution:

快速临时解决方案:

Change webapi to webresources in the url: http://localhost:8080/webapi/myresource

将webapi更改为url中的webresources:http:// localhost:8080 / webapi / myresource

Permanent solution:

Change the file web.xml

更改文件web.xml

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

to

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