Creating a JAX-RS web service
Before you begin
- WebSphere® Application Server traditional v7.0 or later, selecting to install the Feature Pack for Web 2.0 AND MOBILE and the tools for WebSphere Application Server traditional development
If you choose to deploy to a server other than WebSphere Application Server traditional, you cannot use the IBM® JAX-RS library, and must install and configure your own JAX-RS libraries through the Project Facets > JAX-RS preferences page.
Create a JAX-RS enabled web project
About this task
Procedure
Create a JAX-RS web service
Procedure
- In your Web project, create a package (right-click and select ). Import the classes for the web service into the package.
- Open WebContent/WEB-INF/web.xml. In the Design view, select the Servlet JAX-RS Servlet and click Add and add an Initialization parameter to the JAX-RS servlet, leaving the name and value fields empty. Save web.xml ignoring any errors that might be displayed.
- In the Markers view, select the web.xml error about the param-name, right-click and select Quick Fix. Browse to the application and select.
- Add the EAR containing the JAX-RS project to the server and start the server.
Results
Every web application must have a context root for the web application to deploy successfully. A context root for each Web module is defined in the application deployment descriptor during application assembly or during application deployment. The context root is combined with the defined servlet mapping from the WAR file to compose the full URL that users type to access the servlet. The context root for each deployed web application must be unique on the server. The context root can also be empty.
For instance, if a Web application used a context root of sample/application/, the web application request URL begins with http://<hostname>:<port>/sample/application/. The URL pattern of a servlet is appended to the context root of the Web application. For example, if the context root is sample/application/ and the servlet URL mapping is rest/api/*, the base URI for the JAX-RS web application is http://<hostname>:<port>/sample/application/rest/api.
Editing a JAX-RS project
- Library type
- JAX-RS servlet name
- JAX-RS servlet class name
- URL mapping patterns