Trying to do a Hello World with Jersey and Tomcat 10 using IntelliJ as IDE. Unfortunately, I'll get a 404 - it seems the servlet is not loaded. Reading several tutorials, I can't find the reason. Also I'm getting a weird error message in my web.xml...
pom.xml
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
web.xml (xml-file is mandatory, I can't use the ApplicationConfig-class)
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.myapp.hello</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
Also, here I'm getting this error message on the servlet-class
line: 'org.glassfish.jersey.servlet.ServletContainer' is not assignable to 'javax.servlet.Servlet,jakarta.servlet.Servlet'
I only found the https://youtrack.jetbrains.com/issue/IDEA-86833 issue, but it seems to be resolved.
Controller/Endpoint
package com.myapp.hello;
@Path("/hello")
public class DataController {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey Plain";
}
}
This should deploy the servlet and make it accessable under through a GET request with the following url: http://localhost:8080/app/api/hello - but getting a 404 instead...
What am I doing wrong here? Code seems fine, I don't see anything in the server logs.
Thanks for any inputs!