Steps to Run Web App Using CXF_JAX_RS

download Steps to Run Web App Using CXF_JAX_RS

of 18

Transcript of Steps to Run Web App Using CXF_JAX_RS

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    1/19

    Steps to create RESTFul web service using Apache-CXF with the help of JAX-RS

    1. Tomcat

    2. Eclipse Helios

    File->New->Dynamic Web Project

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    2/19

    Click on Finish button

    Expand Demo and open web.xml file

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    3/19

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    4/19

    Add these lines as above and save web.xml file

    contextConfigLocation

    WEB-INF/services.xml

    org.springframework.web.context.ContextLoaderListener

    CXFServlet

    org.apache.cxf.transport.servlet.CXFServlet

    1

    CXFServlet

    /*

    See the above line WEB-INF/services.xmlSo we will create a new file in WEB-INF and save it as services.xml

    Store as services.xml in WEB-INF

    Note the above line in services.xml file. It needs a class called DemoService

    in org.demo.service package.

    Now we will built the class file in src folder.

    Click on Project Explore Tab

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    5/19

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    6/19

    Put the Package: org.demo.service and Name: DemoService

    Click Finish

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    7/19

    Add 2 simple methods to the class with @GET Request Method designatorpackage org.demo.services;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.Produces;

    publicclass DemoService {

    @GET

    @Path("/version")

    @Produces("text/plain")

    public String getVersion(){return"3.0";

    }

    @GET

    @Path("/scope")@Produces("application/xml")

    public String getScope(){return"Scope-1" ;

    }

    }

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    8/19

    Ohh lots of error as we have not included any libraries yet

    Lets add the CXF library. Right click on the Demo folder and click on Properties at

    the bottom

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    9/19

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    10/19

    Click on Add Library. Button on right side

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    11/19

    Select User Library

    Next

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    12/19

    Ok

    Select CXF2-3-0 and Click on Add Jars on right side

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    13/19

    I have all jar files inside a folder that I have downloaded from apach-cxf site. Select

    all jar files then OPEN

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    14/19

    Click on Finish->OK

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    15/19

    See errors gone but 1 moment these jar are not added to your server Tomcat so

    Click on Markers Tab

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    16/19

    Click on Finish button

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    17/19

    Now you are ready to run the application

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    18/19

    Click on Finish

  • 8/6/2019 Steps to Run Web App Using CXF_JAX_RS

    19/19

    http://localhost:8080/Demo/DemoService/version

    http://localhost:8080/Demo/DemoService/scope

    http://localhost:8080/Demo/DemoService/versionhttp://localhost:8080/Demo/DemoService/scopehttp://localhost:8080/Demo/DemoService/versionhttp://localhost:8080/Demo/DemoService/scope