Nov 8, 2018

How to configure / activate REST Services on JBoss EAP 6 / Wildfly 8

There are 3 ways to configure / activate REST Services on JBoss EAP 6 / Wildfly 8. All of them are easy: (The JAX-RS resources are available in the path /WEB_APP_CONTEXT/i88ca.)

1. Subclass javax.ws.rs.core.Application and use the @ApplicationPath annotation.

This is the easiest option and does not require any xml configuration. Simply subclass javax.ws.rs.core.Application in your application and annotate it with the path where you want to make your JAX-RS classes available. For example:

@ApplicationPath("/i88ca")
public class MyApplication extends Application {
}
2. Subclass javax.ws.rs.core.Application and use the web.xml file to set up the JAX-RS mapping.
If you do not wish to use the @ApplicationPath annotation, you still need to subclass javax.ws.rs.core.Application. You then set up the JAX-RS mapping in the web.xml file. For example:
public class MyApplication extends Application {
}
<servlet-mapping>
  <servlet-name>com.acme.MyApplication</servlet-name>
  <url-pattern>/i88ca/*</url-pattern>
</servlet-mapping>
Configuration in web.xml overwrites the @ApplicationPath annotation.
3. Modify the web.xml file.
If you do not want to subclass Application, you can set up the JAX-RS mapping in the web.xml file as follows:
<servlet-mapping>
  <servlet-name>javax.ws.rs.core.Application</servlet-name>
  <url-pattern>/i88ca/*</url-pattern>
</servlet-mapping>
When you choose this option, you only need to add the mapping. You do not need to add the corresponding servlet. The server is responsible for adding the corresponding servlet automatically.