createConfigurationContextFromFileSystem in Axis2

There is a problem when you try to start building web-service of auto-generated Axis2 java model from WSDL file. When you start working on stub, default constructor creates ConfigurationContext with null parameters which means it is empty and therefore you can’t engage any module with thw ServiceClient created from this ConfigurationContext. For example you may want to engage addressing module for dual mode asynchronous web-service implementation as –


And you keep getting error that addressing module can’t be engaged as –

org.apache.axis2.AxisFault: Unable to engage module : addressing
at org.apache.axis2.client.ServiceClient.engageModule(

To overcome this problem, you need to specify the axis2 locations specifically while creating ConfigurationContext. Therefore  instead using default constructor which goes like –

ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null)

, you need to change it to –

ConfigurationContext ctx = 
ConfigurationContextFactory.createConfigurationContextFromFileSystem(repository, path)


Here repository is location of axis2 module/package folder and path is the respective location of axis2.xml (configuration file). Make sure that the respective modules are placed inside modules/repository folder of repository path given. Foe example, you can try following sample code for creating ConfigurationContext - 

ConfigurationContext ctx = 
ConfigurationContextFactory.createConfigurationContextFromFileSystem(“c:\\axis2\\WEB-INF”, “conf/axis2.xml”)

This syntax will work if you have axis2 path set in your class path. Otherwise, you may need to use following syntax - 

ConfigurationContext ctx = 
ConfigurationContextFactory.createConfigurationContextFromFileSystem(“c:\\axis2\\WEB-INF”, “c:\\axis2\\conf\\axis2.xml”)

In this way, you get handle of axis2 modules and related dependencies. Now you can engage any addressing module after ceating the ServiceClient from this ConfigurationContext. The sample code goes as follows –

ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(“c:\\axis2\\WEB-INF”, “c:\\axis2\\conf\\axis2.xml”);

ServiceClient service = new ServiceClient( configContext, null );


Or you can try storing these static path variables in system resources/classpath and then referring them in your code as those variables like –

ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(“axisPath”, “axisXMLPath”);

ServiceClient service = new ServiceClient( configContext, null );


You may also like to visit Apache Axis2 FAQ page –

One thought on “createConfigurationContextFromFileSystem in Axis2”

Leave a Reply

Your email address will not be published. Required fields are marked *