Tutorial: How to create Axis2 web service with IntelliJ IDEA? Part 1: Service side

There is Axis2 plugin for IntelliJ IDEA, but it is not compatible with latest versions. So I lost some time trying to use this plugin. In this post we will not use plugin. Fortunately there is good tool called ant, which will generate some files for us.

What we are going to do? We will not run web service directly from IntelliJ IDEA. Instead of this we need to download Tomcat, install Axis2, install web service manually.

Step 1. Configure Tomcat and install Axis2
Tomcat version 8 is available here. Download and unzip.
Axis2. Download last WAR distibution. WAR file is packaged app which can be very easily installed in Tomcat.

Run Tomcat by executing bin/startup.bat (for Windows) or bin/startup.sh (for Linux/Mac). By default Tomcat will start on port 8080. Type “http://localhost:8080” and if everything is OK Tomcat main page will be opened.


We need access to Apps management page. To do it edit conf/tomcat-users.xml. Add “<user username=”admin” password=”admin” roles=”manager-gui”/>” between <tomcat-users> and </tomcat-users> tags.


In section “WAR file to deploy” deploy axis2.war file.


Then axis2 will appear in the list of applications.


Tomcat and Axis2 are ready, let’s create web service.

Step 2. Create project
Create project (“File”->”New”->”Project…”). We will not use any libraries and frameworks proposed by IntelliJ IDEA.


So structure of our project will be very simple.


Also it is needed to import Axis2 library. We need to download axis2 Binary Distribution from this page. The reason is why we cannot use library from WAR file is that WAR does not contain all libraries. Go to “File” -> “Project Structure…”->tab “Libraries”. Press green plus button and select lib directory from unzipped folder.

Step 3. Write code

In src folder create models directory. In directory create Worker class, which will be used to defined parameters of Worker instance. Write code:

public class Worker {
 public String getName() {
  return name;
 public void setName(String name) {
  this.name = name;
 public String getSurname() {
  return surname;
 public void setSurname(String surname) {
  this.surname = surname;
 public String getPosition() {
  return position;
 public void setPosition(String position) {
  this.position = position;
 public int getSalary() {
  return salary;
 public void setSalary(int salary) {
  this.salary = salary;
 private String name;
 private String surname;
 private String position;
 private int salary;

Little hint. You can type only write
 private String name;
 private String surname;
 private String position;
 private int salary;

then press “Alt”+”Insert”->”Getter and Setter”->Select all fields by “Shift”->”OK”.

Create “CustomService” class in src folder. Define needed functions. I wrote:

public Worker getWorkerWithChangedSalary(Worker worker){
 return worker;

Step 4. Create configuration files

Create directory “resources” in root of project, then create “META-INF” inside of “resouces”. Put file services.xml in “META-INF” with the content below:
<service name="CustomService" scope="application" targetNamespace="http://doszhan.com/">
  My Custom Service
  <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
  <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
 <schema schemaNamespace="http://doszhan.com/xsd"/>
 <parameter name="ServiceClass">CustomService</parameter>

Create file build.xml:
<project name="ForAnt" basedir="." default="generate.service">
 <property environment="env"/>
 <property name="build.dir" value="build"/>
 <path id="axis2.classpath">
  <fileset dir="PATH_TO_AXIS2_LIB">
   <include name="*.jar"/>
 <target name="compile.service">
  <mkdir dir="${build.dir}"/>
  <mkdir dir="${build.dir}/classes"/>
  <mkdir dir="${build.dir}/resources"/>
   <javac debug="on"
 <target name="generate.wsdl" depends="compile.service">
  <taskdef name="java2wsdl"
  <java2wsdl className="CustomService"
    <pathelement path="${axis2.classpath}"/>
    <pathelement location="${build.dir}/classes"/>
 <target name="generate.service" depends="compile.service">
  <copy toDir="${build.dir}/classes" failonerror="false">
   <fileset dir="${basedir}/resources">
    <include name="**/*.xml"/>
  <jar destfile="${build.dir}/CustomService.aar">
   <fileset excludes="**/Test.class" dir="${build.dir}/classes"/>
 <target name="clean">
  <delete dir="${build.dir}"/>

build.xml is for ant. How you see, in build.xml defined operations compile.service, generate.wsdl and generate.service. Pay attention to PATH_TO_AXIS2_LIB. Here you need to define axis2 library folder.

In the end of this step project directory will look like this:

Step 5. Build
To build the project we need to use Ant plugin for IntelliJ IDEA. Click on “Ant Build” on the right side of window. If there is no such button you can use hotkey “Ctrl”+”Shift”+”A” and write “Ant Build”.
Press green plus icon and select build.xml:


Double click on generate.service and our service file generated in folder build. Copy CustomService.aar file into TOMCATE_HOMEwebappsaxis2WEB-INFservices.

Then type http://localhost:8080/axis2/services/listServices in internet browser. If you see page below, you have successfully build and install service


If you have found a spelling error, please, notify us by selecting that text and pressing Ctrl+Enter.

Profile photo of Doszhan Kalibek

Doszhan Kalibek