英文:
Jersey 2.25 and Tomcat 9.0.33 always responding 404 Not found
问题
以下是翻译好的内容:
我已经搜索了这么多天,但找不到任何解决方案或问题所在,所以请不要将问题标记为重复,因为它确实不是重复的。我阅读了所有的问题和答案,尝试了所有的解决方案,但仍然不起作用。
我正在使用Intellij,Jersey 2.25和Tomcat 9.0.33。我不被允许使用maven,所以我手动下载了所有的jar依赖,然后通过将它们添加到项目结构窗口中的库和构件中进行引用。
服务器已经成功部署,当我打开http://localhost:8080/ofar_war_exploded/时,它显示了index.jsp文件的内容。然而,当我尝试访问一个资源,例如在我的OptimizerResource类中返回字符串的简单方法时,我得到了以下响应:
HTTP状态404 - 未找到
状态报告类型
描述:源服务器未找到目标资源的当前表示,或者不愿透露该资源的存在。
Apache Tomcat/9.0.33
lib文件夹包含所有所需的依赖项。我还尝试将lib文件夹添加到WEB-INF内,但得到了相同的行为。
这是我正在使用的所有jar的列表。
这是web.xml文件的内容。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>Optimizer Service</display-name>
<servlet>
<servlet-name>optimizer</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>rest.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>optimizer</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
仅为了测试,我在OptimizerResource类中添加了一个只返回"hello"的get方法。当我尝试请求此URL http://localhost:8080/ofar_war_exploded/rest/optimizer/hello 时,我收到404未找到的响应。
@Path("optimizer")
public class OptimizerResource {
@GET
@Path("hello")
@Produces("text/plain")
public String getHello() {
return "Hello";
}
}
英文:
I have been searching for so many days and I can't find any solution or where is the problem so please don't mark the question as repeated because it's really not. I read all the questions and the answers, I tried all the solutions and still not working.
I am using Intellij, Jersey 2.25 and Tomcat 9.0.33. I am not allowed to use maven so I download all the jar dependencies manually and then reference them from the project structure window by adding them to the libraries and artifacts.
The server is deployed successfully and when I open http://localhost:8080/ofar_war_exploded/ it shows the content of the index.jsp file. However, when I try to access a resource for example a simple method that returns a string in my OptimizerResource class I get the following response
HTTP Status 404 – Not Found
Type Status Report
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.33
The lib folder contains all the dependencies needed. I tried to add also the lib folder inside WEB-INF I got the same behavior.
This is the list of all the jars I am using
This is the content of the web.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>Optimizer Service</display-name>
<servlet>
<servlet-name>optimizer</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>rest.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>optimizer</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Just for a testing wise I added only one get method in the OptimizerResource class that returns hello. When I try to request this url http://localhost:8080/ofar_war_exploded/rest/optimizer/hello
I receive 404 not found.
@Path("optimizer")
public class OptimizerResource {
@GET
@Path("hello")
@Produces("text/plain")
public String getHello() {
return "Hello";
}
}
答案1
得分: 1
以下是翻译好的部分:
在依赖项中出现了一个错误,它们是不正确的。
工作的依赖项集如下:
依赖项列表
所有Jersey捆绑包的完整依赖项列表
<a href="https://repo1.maven.org/maven2/org/glassfish/jersey/bundles/jaxrs-ri/">链接</a>
或者,您可以从此<a href="https://repo1.maven.org/maven2/org/glassfish/jersey/bundles/jaxrs-ri/2.26/jaxrs-ri-2.26.zip">链接</a>下载Jersey的完整依赖项捆绑包。
英文:
There were a mistake in the dependencies, they were incorrect.
The working set of dependencies are as follow:
List of Dependencies
The List of all jersey bundles with complete dependencies
<a href="https://repo1.maven.org/maven2/org/glassfish/jersey/bundles/jaxrs-ri/">Link</a>
Or you can download jersey download the full dependencies bundle from this <a href="https://repo1.maven.org/maven2/org/glassfish/jersey/bundles/jaxrs-ri/2.26/jaxrs-ri-2.26.zip">Link</a>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论