Skip to end of metadata
Go to start of metadata

Axis2 deployer is an extension point in Apache Axis2 where a user can write a new deployer for deploying artifacts. What a deployer does is that it will look for additions/deletions and modifications of a defined file extension(s) in a specified directory and will execute the logic in the deployer implementation. In the Carbon platform, this extension is being used to deploy different types of artifacts such as WAR files, C-Apps and datasources.

The <PRODUCT_HOME>/repository/deployment/server directory is the default location for artifact deployment in all Carbon products. There are different directories (web apps, axis2services etc.) for different artifact types. If you write a deployer that deploys artifacts to the same directory, you get the advantage of deployment synchronization and tenant awareness by default.

Writing an Axis2 Deployer involves the following: 

Implementing the org.apache.axis2.deployment.Deployer interface 

This contains the logic for the initialization, deployment and removal of artifacts. Note that when an artifact is modified, both the undeploy() and deploy() methods will be called.

package org.wso2.carbon.extensions.deployer;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.deployment.Deployer;
import org.apache.axis2.deployment.DeploymentException;
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;

public class SampleDeployer implements Deployer {
  private static Log log = LogFactory.getLog(SampleDeployer.class);
  public void init(ConfigurationContext configurationContext) {
      // initialization code goes here
      log.info("initializing the sample deployer");

  public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
      // file processing code when deploying goes here
      File file = deploymentFileData.getFile();
      log.info("File being deployed: " + file.getName());

  public void setDirectory(String directory) {
      // this can be used to get the directory against which the deployer is registers

  public void setExtension(String fileExtension) {
      // this can be used to get the file extension against which the deployed is registered

  public void undeploy(String filePath) throws DeploymentException {
      // logic at undeployment goes here.
      // NOTE: since the file is already deleted, we don't have a reference to a file at this point
      log.info("File being undeployed: " + filePath);

  public void cleanup() throws DeploymentException {
      // this method gets called when the deployer is unloaded
      log.info("Cleaning up sample deployment");

Writing an OSGi component

Given below is a sample OSGi component.

package org.wso2.carbon.extensions.deployer.internal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
* @scr.component name="org.wso2.carbon.extensions.deployer.SampleDeployer"
* immediate="true"
public class SampleDeployerSC {
  private static Log log = LogFactory.getLog(SampleDeployerSC.class);
  protected void activate(ComponentContext componentContext) {
      log.info(this.getClass().getName() + " activated");
  protected void deactivate(ComponentContext componentContext) {
      log.info(this.getClass().getName() + " deactivated");

Configuring the deployer

The following are the steps for configuring the new deployer in your product:

  1. The component.xml file in the <PRODUCT_HOME>/resources/META-INF directory should be updated with the following details:

    • <directory>: The sub directory (in the <PRODUCT_HOME>/repository/deployment/server directory) that is associated with the deployer.
    • <extension>: The file extension associated with the deployer.
    • <class>: The class implementation, which is org.apache.axis2.deployment.Deployer.

    Note that users can register the same deployer implementation for different file extensions and/or different directories. Given below is a sample component.xml file.

    <component xmlns="http://products.wso2.org/carbon">
  2. Add <Axis2Deployer>CustomDeployer</Axis2Deployer> under configuration/instructions in the pom.xml of the maven-bundle-plugin. Shown below is the a sample pom.xml that is updated for the above deployer.

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
              <name>WSO2 internal Repository</name>

Building the bundle

You can now build the bundle and place it in <PRODUCT_HOME>/repository/components/dropins directory.

  • No labels