'Tomcat error messages for JavaEE REST API
I am trying to build a REST API using JavaEE and Apache Tomcat. I have some instructions on how to retrieve endpoint's message but it doesn't seem to be working for a reason I don't understand.
Java HelloWorld.java:
@Path("HelloWorldService")
public class HelloWorld {
@GET
@Path("/HelloWorld/{name}")
@Produces(MediaType.TEXT_PLAIN)
public String sayHelloWorld(@PathParam("name") String name) {
return "Hello world from" + name;
}
}
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>SCRM</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
When I build an open Tomcat to browser the URL has .war exploded artifact. But I am trying to hit the endpoint as follows:
http://localhost:8080/SCRM/rest/HelloWorldService/HelloWorld/mike
Expected value:
Hello world from mike!
Is there any idea on what is going on?
Tools that I am using:
- Intellij IDEA Ultimate
- Java 11
- Jersey 1.19.4 .jars
- Apache Tomcat 9.0.581
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

