Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

jakarta ee - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 ?le. 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 speci?cation 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 speci?cation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...