Creating a JAX-RS web service
Before you begin
- WebSphere® Application Server v7.0 or v8.0, selecting to install the Feature Pack for Web 2.0 AND MOBILE and the tools for WebSphere Application Server development
If you choose to deploy to a server other than WebSphere Application Server, 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
[WebSphere Application Server traditional] WebSphere Application Server traditional V9 supports JAX-RS 1.1 and higher. The version of JAX-RS that you use in your project must match the version of JAX-RS that you use in your installation of WebSphere Application Server traditional V9. If these versions do not match, the tools display a warning when you deploy your project to the server. If you create a JAX-RS project without specifying a facet level, the tools use JAX-RS 2.0 by default.
com.ibm.ws.jaxrs.jar
com.ibm.ws.prereq.jaxrs.jar
javax.j2ee.jaxrs.jar
com.ibm.ws.jaxrs20.jar
com.ibm.ws.prereq.jaxrs20.jar
javax.ws.rs-api-2.0.jar
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. Saveweb.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