Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JAX-RS needs a war module?

Does JAX-RS needs an web-module WAR or am i doing something wrong?

Every tutorial states to config the rest-service in web.xml. But in ejb-module there is no web.xml. Must I create a WAR just for the rest service?

In my ejb module I want to expose a EJB as a rest service but cannot get it to work. Calling "localhost:8080/EjbModule/rest/test/method" leads to 404

Project structure

- ear
    - EjbModule.jar

Code

Exposing a Bean as a JAX-WS web service and testing it in browser is no problem.

@ApplicationPath("rest")
public class RestApplication extends Application
{
    @Override
    public Set<Class<?>> getClasses()
    {
        final Set<Class<?>> classes = new HashSet<>(1);
        classes.add(TestService.class);
        return classes;
    }
}


@Stateless
@Path("/test")
public class TestService
{
    @Path("/method")
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String test()
    {
        return new Date().toString();
    }
}

Environment: Glassfish 4.0

Edit:

Creating a separate WAR the rest service works as expected.

like image 689
djmj Avatar asked Jun 13 '14 01:06

djmj


1 Answers

From the JAX-RS Specification 2.0 p. 8:

2.3.2 Servlet

A JAX-RS application is packaged as a Web application in a .war file. The application classes are packaged in WEB-INF/classes or WEB-INF/lib and required libraries are packaged in WEB-INF/lib. See the Servlet specification for full details on packaging of web applications.

This is the standard way if you want to deploy your JAX-RS application in a web-container. However the specification points also out that applications can run in different containers like ejb-containers or even an Java SE environment. But for other containers there is nothing specified:

An implementation MAY provide facilities to host a JAX-RS application in other types of container, such facilities are outside the scope of this specification.

like image 172
lefloh Avatar answered Sep 18 '22 13:09

lefloh