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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With