Search code examples
mavenjakarta-eejax-rsear

find path to JAX-RS resource


I just can't find out the path to access my JAX-RS resource which is deployed to wildfly.

ear.ear pom:

<parent>
    <artifactId>jee-services</artifactId>
    <groupId>org.mycompany</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>
<packaging>ear</packaging>
<modelVersion>4.0.0</modelVersion>
<artifactId>ear</artifactId>
<dependencies>
    <dependency>
        <groupId>org.mycompany</groupId>
        <artifactId>ejb_book</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>ejb</type>
    </dependency>
</dependencies>

ejb_book pom:

<parent>
    <artifactId>jee-services</artifactId>
    <groupId>org.mycompany</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>ejb</packaging>
<artifactId>ejb_book</artifactId>

application config

@ApplicationPath("/resources")
public class ApplicationConfig extends Application {
}

resource

@Stateless
@Path("/books")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class BookResource extends AbstractFacade<Book> {
    @PersistenceContext
    private EntityManager entityManager;

    @GET
    @Path("/getBooks")
    public Book getBook() {
        return new Book();
    }

I think the issue is that I'm packaging my ejb_book.jar into ear.ear (where I collect all other ejb-modules)

I tried:

localhost:8080/ear/resources/books/getBooks

and many other combinations but none of them worked.

The application deploys fine to the WildFly server.

BTW: is there a tool to help people access their JAX-RS resource? From the IDE for example. So my question wouldn't be a problem anymore.


Solution

  • According to the JAX-RS 2.0 specification, section 2.3.2 Servlet

    A JAX-RS application is packaged as a Web application in a .war file.

    Since you're not packaging your application as a WAR module and neither you have a WAR module in your EAR, you're not providing a context-root to your (web) application.

    This is preventing you from accessing your REST API through the desired way:

    http://localhost:8080/<context-root>/resources/books/getBooks
    

    As a solution, you could either package your entire application as a WAR, placing the application classes in WEB-INF/classes or WEB-INF/lib and required libraries in WEB-INF/lib, or you could maintain the use your EAR, adding to it a WAR module.