Of course! Let's dive into creating a Java web service using Apache Axis. It's a classic technology that's great for understanding the fundamentals of SOAP web services, even though more modern frameworks like Spring Boot with JAX-RS are more common today.

This guide will cover:
- What is Apache Axis? (A brief overview)
- Step-by-Step Tutorial: Creating a simple "Hello World" web service.
- How to Deploy and Test the service.
- How to Create a Client to consume the service.
- Important Considerations: Pros, cons, and modern alternatives.
What is Apache Axis?
Apache Axis is an open-source, Java-based framework for creating and consuming SOAP (Simple Object Access Protocol) web services. It was one of the first widely adopted frameworks for this purpose and helped popularize the use of web services in the Java world.
There are two main versions:
- Axis 1 (Legacy): The original version. It's relatively simple to use for basic services but has known limitations and is considered legacy.
- Axis 2 (Current): A complete rewrite of Axis 1. It's more modular, performant, and standards-compliant (with JAX-WS), but has a steeper learning curve.
For this tutorial, we'll use Axis 1 because it's the most straightforward for a "getting started" example.

Step-by-Step Tutorial: Creating a "Hello World" Web Service with Axis 1
We will create a simple web service that takes a name as input and returns a greeting.
Prerequisites
- Java Development Kit (JDK): Version 8 or higher.
- Apache Ant: Axis 1 uses Ant for its build process. Make sure it's installed and in your
PATH. - Apache Axis 1: Download the binary distribution from the Apache Axis 1 Archive. We'll use
axis-bin-1_4.zip.
Step 1: Set Up the Project Structure
Create a new directory for your project, for example, AxisHelloWorld. Inside it, create the following structure:
AxisHelloWorld/
├── build.xml (Ant build script - we will create this)
├── src/
│ └── com/
│ └── example/
│ └── webservice/
│ └── HelloWorld.java (Our service implementation)
└── web/
└── WEB-INF/
└── web.xml (Deployment descriptor)
Step 2: Create the Service Implementation Class
This is the plain Java class that contains the business logic. Axis will use this to create the web service interface.
File: src/com/example/webservice/HelloWorld.java

package com.example.webservice;
// This is the implementation class for our web service.
public class HelloWorld {
/**
* A simple method that takes a name and returns a greeting.
* @param name The name to greet.
* @return A greeting string.
*/
public String getGreeting(String name) {
if (name == null || name.trim().isEmpty()) {
return "Hello, Stranger!";
}
return "Hello, " + name + "!";
}
}
Step 3: Create the Ant Build Script (build.xml)
This is the most crucial part. The build.xml file tells Ant how to compile your code, generate the web service artifacts (WSDL, server-side stubs), and package the WAR (Web Application Archive) file.
File: build.xml
<project name="AxisHelloWorld" default="deploy" basedir=".">
<!-- Set up classpaths -->
<path id="compile.classpath">
<!-- The Axis 1 JARs -->
<fileset dir="axis-1_4/lib" includes="**/*.jar"/>
<!-- The Servlet API (usually provided by the web server) -->
<fileset dir="axis-1_4/lib" includes="axis-ant.jar"/>
</path>
<!-- 1. COMPILE: Compile the source code -->
<target name="compile" description="Compile the source files">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes" includeantruntime="false">
<classpath refid="compile.classpath"/>
</javac>
</target>
<!-- 2. GENERATE: Generate WSDL and server-side skeletons -->
<target name="generate" depends="compile" description="Generate WSDL and server-side skeletons">
<!-- This task generates the WSDL and server-side Java files from the service class -->
<axis-java2wsdl
className="com.example.webservice.HelloWorld"
location="http://localhost:8080/axis/services/HelloWorld"
namespace="http://example.com/webservice"
output="build/HelloWorld.wsdl"
/>
</target>
<!-- 3. PACKAGE: Create the WAR file -->
<target name="package" depends="generate" description="Package the WAR file">
<war destfile="dist/AxisHelloWorld.war" webxml="web/WEB-INF/web.xml">
<!-- Add your compiled classes -->
<lib dir="axis-1_4/lib">
<include name="axis.jar"/>
<include name="commons-discovery.jar"/>
<include name="commons-logging.jar"/>
<include name="jaxrpc.jar"/>
<include name="saaj.jar"/>
<include name="log4j-1.2.15.jar"/>
</lib>
<classes dir="build/classes"/>
<!-- The generated WSDL file should be in the web services directory -->
<fileset dir="build" includes="*.wsdl"/>
</war>
</target>
<!-- 4. DEPLOY: Deploy the WAR file to a Tomcat server -->
<target name="deploy" depends="package" description="Deploy the WAR to Tomcat">
<!-- Assumes Tomcat is running on localhost:8080 and manager app is configured -->
<deploy
url="http://localhost:8080/manager/text"
username="your_tomcat_user"
password="your_tomcat_password"
path="/AxisHelloWorld"
warfile="file:${basedir}/dist/AxisHelloWorld.war"
/>
</target>
</project>
Important: Before running this, you must:
- Extract
axis-bin-1_4.zipinto your project directory. - Update the
usernameandpasswordin thedeploytarget to match your Tomcat manager credentials.
Step 4: Create the Deployment Descriptor (web.xml)
This file tells the servlet container (like Tomcat) how to handle requests for our web service.
File: web/WEB-INF/web.xml
<?xml version="1.1" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!-- This is the standard Axis servlet -->
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<!-- Map all requests to /services/* to the Axis servlet -->
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<!-- Welcome file list -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
How to Deploy and Test
-
Start Tomcat: Make sure your Apache Tomcat server is running.
-
Run Ant: Open a command prompt in your project's root directory (
AxisHelloWorld) and run the Ant command:ant deploy
This will execute the
deploytarget inbuild.xml, which in turn will compile, generate, package, and deploy your WAR file to Tomcat. -
Verify Deployment: Open your browser and go to the Axis service list page:
http://localhost:8080/axis/You should seeAxisHelloWorldlisted as a deployed service. -
Test the Service:
- Click on the
HelloWorldlink in the service list. - This will take you to the service's testing page.
- In the
getGreetingoperation's field, enter a name (e.g., "Alice"). - Click the
Invokebutton.
You should see an XML response like this:
<ns1:getGreetingResponse xmlns:ns1="http://example.com/webservice"> <ns1:getGreetingReturn>Hello, Alice!</ns1:getGreeting
- Click on the
