1

I followed a tutorial and the project don't work. When I deploy the war in tomcat and access the address http://localhost:8080/queroquero/rest/vendedor/get I have 404 status, but if I access http://localhost:8080/queroquero/ I get a "Hello world".

@ApplicationPath("rest")
public class Main extends Application{ }
---------------------------------------------
@Path("vendedor")
public class VendedorResource {

    @GET
    @Path("get")
    @Produces(MediaType.APPLICATION_JSON)
    public Response get() {
        String texto = new String("It's working!!!");
        return Response.ok(texto).build();
    }
    
}

My POM.xml dependencies:

<dependencies>
    <dependency>
        <groupId>jakarta.platform</groupId>
        <artifactId>jakarta.jakartaee-api</artifactId>
        <version>8.0.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>2.3.3</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.7</version>
    </dependency>
  </dependencies>

My web.xml:

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <!-- Auto scan REST service -->
</web-app>

I'm already spent hours and cannot find what is wrong or missing.

MoabR
  • 11
  • 1
  • 5
  • Does this answer your question? [I'm using JakartaEE and making a "hello world" kind of restfulAPI, can't get a return string by visiting URL](https://stackoverflow.com/questions/69000553/im-using-jakartaee-and-making-a-hello-world-kind-of-restfulapi-cant-get-a-r) – Piotr P. Karwasz Nov 03 '21 at 19:40
  • If you are using Tomcat 9 instead of Tomcat 10 you need to downgrade each artifact in the above answer by one major release (e.g. use 2.35 for Jersey). Tomcat's list of supported APIs can be found in [this answer](https://stackoverflow.com/a/67915320/11748454). – Piotr P. Karwasz Nov 03 '21 at 19:43
  • What Tomcat version are you using? – Mark Rotteveel Nov 06 '21 at 12:20
  • @MarkRotteveel I'm using Tomcat 10 – MoabR Nov 08 '21 at 13:50
  • @MoabRodrigues If you're using Tomcat 10, then you need to load Jakarta EE 9.x libraries (`jakarta.*` packages), currently your loading Jakarta EE 8.x or lower libraries (`javax.*` packages). Alternatively, you need to downgrade to Tomcat 9. – Mark Rotteveel Nov 08 '21 at 19:19
  • @MarkRotteveel I not tested you proposal of solution, but when I change the implementation of JAX to Jersey it works fine. – MoabR Nov 25 '21 at 19:16

2 Answers2

0

Probably you need to improve your @Path definition?: as far as I know you should put:

@Path("/rest")
@Path("/venderdor")
@Path("/get")
Antonio E.
  • 359
  • 1
  • 9
  • 27
0

So guys, The problems was a conflit genereted by the maven imports. As far a change the libraries looking for compability I got the results. The main change was to change the Jakarta implementation of JAX for Jersey implementation. If anyone wants to know how I did it, just check the complete code in github (Rest code). Unfortunately I did not have time to discover what is the correct versions of jakarta implementation, which of them to match. I will share here the dependencies of pom.xml:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
            <!-- artifactId>jersey-container-servlet</artifactId -->
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
        </dependency>
        
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.7</version>
        </dependency>
        
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.27</version>
        </dependency>
    </dependencies>
MoabR
  • 11
  • 1
  • 5