Java Web Service using Eclipse

This tutorial is to create a java web service and client using Eclipse IDE. We will go by lazy way and use Eclipse wizard to generate the web service and client. Previously I wrote a tutorial to create a java web service using NetBeans and based on popular request I am writing this tutorial.

There are two ways to develop a web service namely top-down approach and bottom-up approach. To know about these approaches and in general about web service refer my introduction to web service tutorial posted earlier. We will be using bottom-up development approach in this tutorial.

Eclipse has many different versions and remember to use the Java EE IDE. It comes bundled with necessary plugins.

Just for your information, Eclipse by default uses Apache Axis to implement the web service and it provides option to use our choice of web service engine. I decided to go with the default bundled Apache Axis.

1. Create a Dynamic Web Project

Use the new project from menu and open project wizard. Select ‘Dynamic Web Project’ and click next. Then give a project name and select a target runtime (I have Apache Tomcat v7.0) and leave all other default values and click next to finish.

Create a New Runtime

If the run time is not already defined, then click New Runtime and select the version of Tomcat you have installed (already) then click next. Now browse the path of Tomcat home directory and click finish.

2. Create Web Service Provider Java Class

Create a new package under ‘Java Resources – src’ named com.javapapers.jee Then, create a new java class under that package. This is the web service’s service provider class.

I have used the above for my service. This is a simple service which will return type of animal based on argument passed.

With this step everything is over. If you have Eclipse it will take care of all the remaining work like creating web service, generating wsdl, skeleton, service client, stub and etc etc. Imagine how it would be if we have an Eclipse to help us in living our daily life. Eclipse for bathing, eating, … just sit and click eating is done. Crazy isn’t it? That is how the remainder of web service creation is going to be, just click click. IDE is helping us to do our job better but sometimes I think it makes us lazy. If you are a beginner, you must know what is happening behind the screens for every click in the Eclipse wizard.

3. Create a Web Service

Now the service class is ready and we need to create a web service using this java class.

Right click on ‘Java Resources’ -> New and select ‘Web Service’ under ‘Web Services’ folder from the wizard. Click Next button.

Select Service Implementation

In this Web Service wizard, use the browse button and select the java class written earlier. Which is our service implementation java class.
Then, drag the slider bar to upper most in both service and client part.
Then, enable the Publish the Web service check box.

Web Service Client Creation

Added to configuring the service implementation, we are instructing Eclipse to generate a web service client also. This will create a dynamic web java project and create a web service client for the web service created. Instead we can also create a java project and write a client to access the web service.

Deploy Web Service and Client

Click Next till the Server Starup wizard and then click Start Server. This step will start the associated runtime Tomcat.

4. Test Web Service

We can test the web service using a web service client. For this we need to create web service client application. In our previous configuration we moved the slider above in service configuration wizard which will create a web service client application.

Eclipse Web Service Explorer

There is one more way, Eclipse provides a Web Service Explorer. It is a nice client that will help us test a web service client.

Then click Next to reach ‘Test Web Service’ wizard and then click Launch button.

Web Service Client Application

Then click next next and we will see the web service client application generated. See in the image below, EclipseWebServiceClient is a web application generated by Eclipse.

Do not stop with this. Open the EclipseWebServiceClient application and go through the code and generated Stub, Proxy and all the files. It will really help to understand more.

I think here we used JAX-RPC(I donot know why we have to use JAX-RPC, do we have any other option which will work for any technology), Would you able to explain how JAS-WS make calls to java service the methods, I am bit confused with, how really xml to java object initiation happens.

Hi sorry, I am keep on asking questions. When I try with list of objects to return my webservice I am getting below error.
“java.util.List”, that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

What is the use by implementing the above service as a web service rather than implementing it as a simple website by creating a html input tag and then submit the request to a php or jsp page where the server sends you a response saying it is wild or domestic or what ever ..PLEASE COMMENT/REPLY

if possible please explain the code and generated Stub, Proxy and all the files.
we should understand the underlying technology and whats happening at the background.we should not rely or depend on IDEs. Today u work in one IDE but tomorrow another and again another..u should not learn the procedure in IDE ..u need to understand the underlying technology and architecture.PLEASE EXPLAIN

The error on the console is as follows.
21:42:02,025 ERROR [MainDeployer] Could not initialise deployment: file:/C:/jbos
s-4.2.3.GA/server/default/deploy/Proj_jp_webEAR.ear
org.jboss.deployment.DeploymentException: No META-INF/application.xml found

This is great tutorial for the beginner likes me.!!
but please describe more about how it’s working behind of IDE implementation,how I can do all process in webservice creating such as wsdl ,coding stub etc. And I want to know how can I use json files with the webservice .

We are created web services url using eclipse axis 2 IDE and also deployed into jboss server.
Every thing working fine, but server logs are getting warnings like
”
WARN[org.apache.axis2.classloader.BeanInfoCache] Unable to locate a BeanInfo cache for class webService.greenPages.Category (stopClass=class java.lang.Object). This will negatively affect performance!
”
Any body idea on this.

Hi joe,
I tried a lot . But i am not able to create
a webservice . In start server page when i
am trying to start the server it is not able to start properly .
next button is not enabling .serverconfig.xml also
Not generating . I am using jboss 4.0.2
Plz help

[…] web services in Java. We saw about SOAP based hello world web services and how to create them using Eclipse and Netbeans. Now this tutorial is about getting started with Axis2 based webservice using […]

I’m trying to create WSDL using MyEclipse 10 taking JAX-WS(Websphere)Version 2.1
Here in my code, I’m passing File as a input parameter but when I try to generate WSDL I get the following error, Please help me if there is a way to pass input as file(java.io.File)
The following warnings were generated while running WSDL2Java. Press Cancel to abort the generation process.
Jun 4, 2013 10:46:25 AM com.ibm.ws.webservices.wsdl.fromJava.BeanWriter isBeanCompatible
WARNING:

WSWS3292W: Warning: The class java.io.File is defined in a java or javax package and cannot be converted into an xml schema type. An xml schema anyType will be used to define this class in the wsdl file.

WSWS3292W: Warning: The class java.io.File is defined in a java or javax package and cannot be converted into an xml schema type. An xml schema anyType will be used to define this class in the wsdl file.

WSVR0615W: The user.install.root system property is not set. Some product classes might not be found.

I got the same error: “Error when deploying Web service to Axis runtime”.
The issue was…the default tomcat port 8080 is already in use, when i changed that…i could directly execute the example….thanks joe

Thanks for the clear crispy and summary tutorial.
just one question, when the web service created, why i get a JSR-109 Web Services project in the Project Explorer? and even if I delete my web service project, the JSR-109 Web Services still exist and can not do anything on it(delete, close ), would You have time helping me to solve this question?

I have tried to create the web service, but as you said after creating the service class I have tried to create the web service but it’s not showing the service class in the browsing pop can any one suggest.

Hi,
I’m having a problem while create the web service.After my server start to run I’m getting Error like ‘IWAB0489E Error when deploying Web service to Axis runtime ‘ .Can you please tell me how to fix this?

Thank for this tutorial.
I have created a web service using the same but when I am trying to run it another time after closing it, get an error of 404. So do I need to overwrite the created web service or any other thing(s) needed to be done in order to run again that web service.

Hello Joe, I am new to web service creation with Eclipse and your blog was very useful.
I have the following concerns and I need your help:
1. What is the difference between a dynamic project, webservice project and a web application project in Eclipse?
2. Which kind of project is used when/where?
3. When and Where should I use JAX-WS? because, the dynamic project in your tutorial dint need that.
4. To modify/check SOAP headers, do I need servlets and handlers and a whole different configuration of webservice?
Eclipse has automated everything that I am not able to understand when what happens where.
5. Could you please provide such a tutorial (or link to one similar) for creating a (common) webservice to send push notifications to GCM/APNS/BB depending upon a set of parameters from client app?

HiJoe,
Example is nice.Am very new to webservices,here in your example service we have created ,client also created. But to consume that service we need to add some classes in client.So that we can check we can consume the service.

hi sir
i created a web service in java and trying to cal from dot net c#
when i’m adding wsdl reference i’m getting the error in tomcat console.

org.apache.axis.transport.http.AxisServlet getSoapAction
SEVERE: Generating fault class
AxisFault
faultCode: {http://xml.apache.org/axis/}Client.NoSOAPAction
faultSubcode:
faultString: no SOAPAction header!
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:no SOAPAction header!
at org.apache.axis.transport.http.AxisServlet.getSoapAction(AxisServlet.java:1013)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:678)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

{http://xml.apache.org/axis/}hostname:1-PC

no SOAPAction header!
at org.apache.axis.transport.http.AxisServlet.getSoapAction(AxisServlet.java:1013)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:678)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Feb 14, 2014 10:32:53 AM org.apache.axis.transport.http.AxisServlet getSoapAction
SEVERE: Generating fault class
AxisFault
faultCode: {http://xml.apache.org/axis/}Client.NoSOAPAction
faultSubcode:
faultString: no SOAPAction header!
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:no SOAPAction header!
at org.apache.axis.transport.http.AxisServlet.getSoapAction(AxisServlet.java:1013)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:678)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

{http://xml.apache.org/axis/}hostname:1-PC

no SOAPAction header!
at org.apache.axis.transport.http.AxisServlet.getSoapAction(AxisServlet.java:1013)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:678)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

after doing all the things right when i create a web service im getting error like
“Unable to add the follwing facets to project Ws: Axis2 Web Services Extensions, Axis2 Web Services Core”
I have no idea about it..plz help

hi Joe,
it’s a nice explanation.I developed the web service in netbeans and added more functions.

but it’s the first time I’m developed the web service using eclipse . But dont know how to add new method in same web service and getting targetNamespace and wsdl url. i need targetNamespace and wsdl url because my client is an android phone.

can you please give me a solution to add new method in same web service and how to get wsdl url and name space.

hi Joe,
it’s a nice explanation.I developed the web service in netbeans and added more functions.

but it’s the first time I’m developed the web service using eclipse . But dont know how to add new method in same web service and getting targetNamespace and wsdl url. i need targetNamespace and wsdl url because my client is an android phone.

can you please give me a solution to add new method in same web service and how to get wsdl url and name space. if u can could u please send the answer to my id : srijinits@gmail.com

Having the same problem mayur. Have tried a bunch of examples same results, been workign on this work like a week, real fustrating. Using JDK 1.8, tomcat 7.0.54, eclipse Kepler. It’s looking like a problem with eclipse versions maybe with compatability with dependant SW?

The service does not deploy, I see no WSDL generated and the AAR is the same version.aar from axis2 and seems ot make a copy of it in the project directory and it’s contents are the same from like 2012 when you open the aar.

Your tutorials are really simple and straight forward and I like it.
In your service class you have String animalType = “”; Please assign the animal parameter to the variable in order to get the desired output.