Nalaka
Nalaka

Reputation: 11

Issue on running a JAVA 13 JAX-RS project in Tomcat 9

I'm working on this simple project and have this problem:

HTTP Status 404 – Not Found
Type Status Report

Message /RestTestThree/myService/Calculator/

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.30

I use this setting: JDK 13, Eclipse 2019-12, Tomcat 9.

I tried different URLs and I hope this one is the correct one:

http://localhost:8080/RestTestThree/myService/Calculator/

I tried both model 3 and 4. Tried different dependencies and versions.

When trying to run this project, at some point the Tomcat even won't start, giving the error

Server Tomcat v9.0 Server at localhost failed to start.

My files are as follows.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.RestTestThree</groupId>
<artifactId>RestTestThree</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>13</release>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.3</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-bundle</artifactId>
        <version>1.17</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.17</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.17</version>
    </dependency>

    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.1.2</version>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
    </dependency>

</dependencies>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>RestTestThree</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>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.Calculator</param-value>  <!--comma separated packages -->
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Simple REST Service</servlet-name>
    <url-pattern>/myService/*</url-pattern>
</servlet-mapping>

Calculator.java

package com;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/Calculator")
public class Calculator
{
    @GET
    @Path("/")
    @Produces(MediaType.TEXT_PLAIN)
    public String hello()
    {
        return "Working...";
    }

    @GET
    @Path("/Add")
    @Produces(MediaType.TEXT_PLAIN)
    public String add()
    {
        return "<div>Sum = 10</div>";
    }
}

Upvotes: 0

Views: 493

Answers (1)

motio
motio

Reputation: 11

I had the same problem. After downgrade java 13 to 11 all work perfect. Need convert project to 11 some.

Upvotes: 1

Related Questions