Create JAX-WS Web Service Using Eclipse

Create JAX-WS Web Service Using Eclipse explains about how to create a JAX-WS web Service using in built Eclipse plugin wizard

Note

You can also read following article without using Eclipse plugin CXF Web Service Tutorial

See Consume JAX-WS Web Service Using Eclipse in order to run this service

How to create jax-ws web service using Eclipse?

Required Libraries

You need to download

  1. JDK 7
  2. Eclipse 3.7
  3. CXF-2.6.1

Steps For Creating JAX-WS Web Service:

1) Firstly create a Dynamic Web Project (File->New->Dynamic Web Project) named "JAXWSEclipse" according to following screenshot

Create Project Create JAX-WS Web Service

2) You need to configure the framework, you can have two options CXF or Axis (We will do this on step 5)

Create JAX-WS Web Service

3) Right Click on our created project(JAXWSEclipse) (File->New->Other->Web Services->Web Service)

Create JAX-WS Web Service

4) We need to create following 3 classes

Create a Student Object

package com.student;

public class Student {
 
private String name;
 
public String getName() {
   
return name;
 
}
 
public void setName(String name) {
   
this.name = name;
 
}
}

Create a Service Interface

This service interface will defines which methods of web service, to be invoked by the client

package com.student;

import javax.jws.WebService;

@WebService
public interface ChangeStudentDetails {
 
Student changeName(Student student);
}

Implement the Service Interface

Here we implement the service interface created on the previous step

package com.student;

import javax.jws.WebService;

@WebService(endpointInterface = "com.student.ChangeStudentDetails")
public class ChangeStudentDetailsImpl implements ChangeStudentDetails {
   
public Student changeName(Student student) {
     
student.setName("Hello "+student.getName());
     
return student;
   
}
}

5) see the project structure below

Create JAX-WS Web Service

6) Just Browse your Web Service Implementation class created on step 4 (com.student.ChangeStudentDetailsImpl), You can also change the Web service runtime by clicking Web service runtime link (see next step)

Create JAX-WS Web Service

7) You can select your Web Service Framework of your choice, You have two options 1) CXF 2)  AXIS (We have configured this on step 2)

Create JAX-WS Web Service

8) Now click Next button, Now you can select existing Service Endpoint Interface

Create JAX-WS Web Service

9) Now click Next button, Now you can annotate @WebMethod, @WebParam, @RequestWrapper, @ResponseWrapper, @WebResult etc (Just tick the checkboxes)

Create JAX-WS Web Service

10) Now click Next button, Now you can see various Java2WS generation options (Just tick the checkboxes) & you can select different SOAP versions (SOAP 1.1 & SOAP 1.2)

Create JAX-WS Web Service

11) Now click Next button, you can see all the artifacts are created, you can also see following logs on console

You can see that Eclipse internally using CXF's java2ws tool inorder to generate artifacts.

java2ws -cp C:\Documents and Settings\test\workspace_test\JAXWSEclipse\build\classes -s C:\Documents and Settings\test\workspace_test\JAXWSEclipse\.cxftmp/src -d C:\Documents and Settings\test\workspace_test\JAXWSEclipse\.cxftmp/wsdl -classdir C:\Documents and Settings\test\workspace_test\JAXWSEclipse\build\classes -o changestudentdetailsimpl.wsdl -soap12 -createxsdimports -verbose -frontend jaxws -databinding jaxb -wsdl -wrapperbean com.student.ChangeStudentDetailsImpl
java2ws - Apache CXF 2.6.1

Nov 15, 2013 10:40:52 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://student.com/}ChangeStudentDetailsImplService from class com.student.ChangeStudentDetails

Create JAX-WS Web Service

Now click Start server to start the server to deploy

Create JAX-WS Web Service

Note

You can Find all the deployed JAX-WS/JAX-RS services you need to append 'services' at the end of the URL so URL will become following

http://localhost:8080/JAXWSEclipse/services

Deployed CXF Web Service

Create JAX-WS Web Service

Note

you can also see Consume JAX-WS Web Service Using Eclipse in order to run this service





Your email address will not be published. Required fields are marked *