September 28, 2020
Hot Topics:

Creating Web Services from J2EE Components

  • By Nandhini Arumugam and Sujata De
  • Send Email »
  • More Articles »

Creating a Web Service from a Java class file

Follow the steps given below to create a Web service from a Java class. Copy myWebService.java into your directory and compile it.

public class myWebService
   public String sayHello(String name)
         return "Hello Guest";
         return "Hello " + name;


The servicegen Ant task will create a myWebService.ear file that can be deployed into Weblogic. Run the following Ant task using the command "ant" from the command prompt.

<project name="buildWebservice" default="build-ear">
   <target name="build-ear">


Once myWebservice.ear is created, deploy it in Weblogic under Deployments->Applications. The URL for accessing this Web service will be http://hostname:portname/servicename. For example, http://localhost:7001/myWebservice/myWebservice.

Note: The style="rpc" attribute specifies that the operations in the Web Service are all RPC-oriented. If the operations in your Web Service are document-oriented, specify style="document" and run the Antbuild.


The real value of Web services lies in the composition of a set of Web services, or what is commonly known as creating a 'flow'. To create a truly versatile business flow suited to every purpose of the target user, Web services have to be developed from various kinds of software components on various technologies, languages, and platforms. The present work addresses the creation of a simple Web service from a variety of J2EE components.

About the Authors

Nandhini Arumugam holds a Masters degree in Computer Applications from PSG College of Technology, Coimbatore. She has worked as a Software Engineer in the Telecom and Mobile Solutions Lab, Hewlett-Packard, Bangalore for more than one year. The domain of her experience includes Web services and J2EE-related technologies. She can be reached at nandhini.arumugam@hp.com.

Sujata De is a Senior Software Engineer for Telecom and Mobile Solutions Lab, Hewlett-Packard, Bangalore. She holdsa Bachelor's degree in Civil Engineering from the Indian Institute of Technology, Kharagpur, followed by Master's degree in Mechanical Engineering from the Indian Institute of Science, Bangalore. She has around three years of industry experience involving quality, Web services, LDAP, UDDI, and J2EE technologies and is currently involved in developing access controllers for Web services. She can be reached at sujata.de@hp.com.

Page 3 of 3

This article was originally published on September 20, 2004

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date