Apache Axis2 - Hello World! using Eclipse

The previous article Apache Axis2 - Hello World! provides step by step guide to develop a very basic Axis2 Hello World application without using any IDEs. This article helps you to create a simple application in Axis2 using Eclipse IDE.

  • Eclipse IDE for Java EE Developers (Follow this link to install Eclipse)
  • Apache Tomcat (Follow this link to install and integrate with Eclipse)
  • Apache Axis2 (Follow this link to install and integrate with Eclipse)

Update (01/05/2017): With the Axis2 library 1.7.4 there are some JSTL related errors in the JSP file. If you get such errors in your project, add the jstl-1.2.jar into the WebContent/lib directories.

Step 1:
Create a new Dynamic Web Project named HelloAxis2 and change the Dynamic web module version to 2.5 because the current version of Axis2 core does not support versions higher than 2.5.

Step 2:
Click on the Modify button in Configuration sub-region.

Step 3:
Check Axis2 Web Services, click OK and click the Finish button.

Step 4:
From Axis2 1.7 onwards, Eclipse fails to copy xmlschema-core library to the project. It will throw NoClassDefFoundError: org/apache/ws/commons/schema/resolver/URIResolver when you run the project. To avoid this exception, copy the xmlschema-core-x.x.x.jar file from $AXIS2_HOME/lib folder to the Eclipse project directory WebContent/WEB-INF/lib.

Step 5:
Create a new package com.javahelps.helloaxis in the src in the src folder and create a new class HelloService inside that package.

Step 6:
Add a method sayHello in the HelloService class as shown below. This is the business logic of our web service.
package com.javahelps.helloaxis;

public class HelloService {

    public String sayHello(String name) {
        return "Hello " + name;

Step 7:
Right-click on the project and select New → Other → Web Service and click ‘Next’

Step 8:
In the appeared dialog, click the Browse button and select the HelloService class as shown below.

Step 9:
Click the “Web service runtime: Apache Axis” link under Configuration and select Apache Axis 2.

Step 10:
Ensure that the “Service project” under Configuration is “HelloAxis2”, which is your project name and click the ‘Next’.

Step 11:
Make sure that “Generate a default services.xml file” is selected and click “Finish”.

Step 12:
From Axis2 1.7 Message Exchange Pattern (MEP) URLS in the form http://www.w3.org/2004/08/wsdl/XXX and http://www.w3.org/2006/01/wsdl/XXX are no longer supported. Instead of them, we need to use http://www.w3.org/ns/wsdl/XXX. (Reference)

Therefore, open the WebContent/WEB-INF/services/HelloService/META-INF/services.xml file and change the messageReceivers as shown below.
<service name="HelloService">
  Please Type your service description here
  <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only"
   class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />

  <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
   class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
 <parameter name="ServiceClass" locked="false">com.javahelps.helloaxis.HelloService</parameter>
Step 13:
Right-click on the project and select Run As → Run on Server, select the Tomcat server and click ‘Finish’.

Step 14:
Click on the ‘Services’ link in the appeared web page. It should list the available services including HelloService. Now we have successfully created our first web service using Axis2.

Step 15:
Click on ‘HelloService’ link and note the URL for future purpose.

Step 16:
From this step onwards we are going to create a client for our web service. Create a new Dynamic Web Project named “Axis2Client” with same configurations as we did in Step 1, 2 and 3.

Step 17:
Copy and paste the xmlschema-core-x.x.x.jar file from $AXIS2_HOME/lib folder to the Eclipse project directory WebContent/WEB-INF/lib as we did in Step 4. If this library is not added to the client project, you may get NoClassDefFoundError: org/apache/ws/commons/schema/utils/NamespacePrefixList error when you run the client.

Step 18:
Right click on the Axis2Client project, select New → Other → Web Service Client and click Next.

Step 19:
Provide the URL noted in Step 15 in place of Service definition and change the “Web service runtime” to Apache Axis2 as we did in Step 9.

It will create HelloServiceStub and HelloServiceCallbackHandler classes in the src folder with a package com.javahelps.helloaxis.

Step 20:
Create a new class Client in the same package com.javahelps.helloaxis and modify the code as shown here.
package com.javahelps.helloaxis;

public class Client {
    public static void main(String[] args) throws Exception {
        // Create the stub object
        HelloServiceStub stub = new HelloServiceStub();

        // Create the request
        HelloServiceStub.SayHello request = new HelloServiceStub.SayHello();

        // Set the parameters

        // Invoke the service
        HelloServiceStub.SayHelloResponse response = stub.sayHello(request);
        String res = response.get_return(); // Hello Gobinath
        System.out.println("Response : " + res);

Step 21:
Save all the changes and run the Client class as a Java application.

Find the project on Git Hub.
Next Post »


Write comments
January 5, 2018 at 5:26 PM delete

Thank you, author. For detailed explanation. Wasted couple days on just settings of Axis2 and integrating with Eclipse. Why there are so many exceptions to keep in mind such changing default services.xml, manually adding those 2 jar files, moreover i configured buildpath by adding xmlschema jar into library tab. So many setting that your brain boils.
Thanks again for information. I would add some explanation for Windows users.

Maliki Moustapha
July 23, 2018 at 4:16 AM delete

Hello, thanks for the article, but i have encountered this small issue. a step No 19 when clicking finish its giving me this error : Exception occurred during code generation for WSDL : org.apache.axis2.AxisFault: No operation found in the portType element
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jst.ws.axis2.consumption.core.utils.WSDL2JavaGenerator.getAxisService(WSDL2JavaGenerator.java:395)
so please what could be the problem ? any help

July 28, 2018 at 6:16 AM delete

I have written this article 2 years ago and did not check Axis2 thereafter. They may break the configurations in a later version. I will give a try and update the article if there are any changes.

June 23, 2020 at 2:03 PM delete

Thank you very mcuh for teh step by step instructions, This helped me to understand things better.


Contact Form


Email *

Message *