< Previous | Next >

Lesson 1: Creating a server and web project

The web service needs to reside in a web project with the JAX-RS facet enabled.

Create a JAX-RS enabled server

About this task

Before creating the web service, you need to have a server which has Java 5.0 or later JVM support defined and started. By default a server is created for you when you install WebSphere Application Server. This server can be seen in the Servers view. However, if you want to create a new WebSphere Application Server do the following:

Procedure

  1. From the File menu, select New > Other > Server > Server > Next.
  2. Select the appropriate version of WebSphere Application Server as the server type. Click Next.
  3. If this runtime has not been created in your workspace, you will be prompted to select the installation directory for the server. Click Next.
  4. Accept the default server port and name. For this tutorial the default server name used will be server1. Click Finish.
  5. Wait for the server to start. After it has started the Console view will display Server server1 open for e-business. If the server does not start automatically select it in the Servers view and click the start icon: server start icon.

Create a JAX-RS enabled web project

About this task

The JAX-RS web service needs to reside in a project with the JAX-RS facet enabled.

Procedure

  1. In the Java EE perspective, right-click your enterprise application project and select New > Web Project to open the web project wizard.
  2. In the Name field, type a name for your new web project. For this tutorial, use JAXRS.
  3. In the Project Templates section, select the type of web template you want to use: For this tutorial, select Simple.
    Option Description
    Dojo Toolkit Configures the project to have Dojo capabilities. The Dojo resources can be in the project itself, a separate project, or a remote location accessible via HTTP.
    JavaServer Faces Enables the project to be deployed with JSF capabilities. Configuration is provided for either JSP or Facelets.
    REST Services A project configured for REST Services based on JAX-RS
    Simple This creates a basic web project.
  4. In the Programming Model section, select the programming model that you want to use: For this tutorial, select Java EE.
    • Client-side only (HTML, JavaScript,...)
    • Java EE
    • OSGi
  5. Click Next to configure your new web project.
  6. On the deployment page, from the list of available configuration options, click Deployment to open the Deployment configuration page.
    • In the Target runtime field, select the WebSphere Application Server that you installed earlier in the tutorial.
    • In the Web module version field, accept the default, which is automatically selected based on which WebSphere Application Server you selected.
    • In the EAR Membership field, select Add project to an EAR, and ensure that JAXRSEAR is the EAR project name.
    • Under the Deployment section, select Change Features. On the Project Facets page, select JAX-RS (REST Web Services), version 1.1, and click OK.
  7. From the list of available configuration options, click Java to open the Java configuration page.
    • In the Source folders on build path field, accept the default src directory, or click Add Folder, Edit... or Remove to specify a folder for your source files.
    • In the Default output folder: field, specify a folder for your output files or accept the default value (WebContent\WEB-INF\classes).
      Important: If you choose a folder other than WebContent\WEB-INF\classes for your default output folder, the problems view reports a warning:
      Single root warning
      The default for single rootedness problems is set to warning. To change this setting, use the Validation Filters for Project Structure Validator page:
      1. Click Window > Preferences > Validation > Project Structure Validation and then the ... button for Settings.
      2. In the Validation Filters for Project Structure Validator page, specify the default severity level. Available severity levels are Error, Warning, and Ignore.
  8. From the list of available configuration options, click REST Services to open the REST Services configuration page. In the JAX-RS Implementation Library field, select IBM WebSphere Application Server v<x> JAX-RS Library. Ensure that the following values appear:
    • In the JAX-RS servlet name: field, ensure that JAX-RS Servlet appears.
    • In the JAX-RS servlet class name: field, ensure that com.ibm.websphere.jaxrs.server.IBMRestServlet appears.
    • In the URL mapping patterns: field, ensure that /jaxrs/* appears.
    Learn more about libraries: The JAX-RS libraries for each WebSphere Application Server that you have installed will be listed in this drop-down box. If you want to use a non-WebSphere library, it can be imported using the User Libraries preference page. If you select User Library, you can launch the User Libraries preference page and add a library. After a project has been created, you can change the library on the Preferences > Project Facets > JAX-RS page.
  9. From the list of available configuration options, click Web Module. On the Web Module configuration page:
    • In the Context root field, type the name of your web project root, or accept the default (which is the name of your web project).
    • In the Content directory field, type the name of your content directory, or accept the default (WebContent).
    • Select Generate web.xml deployment descriptor if you want to create a deployment descriptor. You can also add a deployment descriptor to your web module later.You need to use a web.xml to configure security constraints and other behavior.
  10. Click Finish.

Results

The facet adds the library, servlet information, and support for JAX-RS annotations processing and JAX-RS quick-fixes.

Now you are ready to begin the next module: Creating and testing the web service.

< Previous | Next >
Icon that indicates the type of topic Tutorial lesson topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: jaxrs_exercise12.html