How to create Java webservice in netbeans

In this post, we are going to discuss about how to create webservice in Java using netbeans IDE. Follow below steps to create sample webservice in netbeans IDE.

Step 1: Create project

Open Netbeans >> Select File >> New Project >> Java Web: Web Application:


Click Next >> Enter Project name: ‘HelloWorldWebService’:


Click Next >> Select Server:


Click Finish

Step 2: Create WebService

Right click on the project ‘HelloWorldWebService’ >> New >> Web Service:
Enter Web service name: SayHelloService
Enter Package: com.prgguru.example


Click Finish

Step 3: Add/Update web method

I just modified the name of webmethod from hello to sayHello:

 * To change this template, choose Tools | Templates
 * and open the template in the editor.
package com.prgguru.example;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

 * @author Udhay
@WebService(serviceName = "SayHelloService")
public class SayHelloService {

    /** This is a sample web service operation */
    @WebMethod(operationName = "hello")
    public String sayHello(@WebParam(name = "name") String txt) {
        return "Hello " + txt + " !";

Step 4: Clean and build the application

Right click on the project, select ‘Clean and Build’.


Step 5: Deploy the application

Right click on the project, select ‘Deploy’.


Step 6: Test the webservice

Right click on the web service ‘SayHelloService’ and select ‘Test Web Service’.


It will open up the browser where the service we created can be tested:


Enter the name in the textbox and hit ‘hello’ button, you could see the response from the server as shown below:


Author: Udhay

Share This Post On

Pin It on Pinterest