Deploying Service Archive on Jboss Server (SAR) for startup service


SAR known as Service Archive file is created with the .sar extension same like other archive files (WAR, JAR, EAR) created. There are many things we can achieve with SAR  i.e we can use it like a independent service component, startup service etc..

It gets automatically deployed when application server get starts.  Most of the times these SAR files are used for writing thread related components which have to be running independently.

SAR in JBoss
JBoss’s service archive architecture is based on the Java Extension Management (JMX). During the server bootup process, the service archive deployer (SARDeployer) instantiates the JBoss service classes and exposes them as manageable beans through JMX. You can view all of registered JBoss service components in the JBoss JMX Console web application.

Let’s create and deploy the SAR file on Jboss GA 5.

Dependences required:

Jakarta Commons IO,
Jakarta Commons Logging,
jboss-jmx.jar ,

The Management Interface

 public interface TestServiceMBean implements ServiceMBean {
  //add any other methods
  String getServiceName();

Now we have to implement our management interface and the start/stop lifecyle methods. We must implement our management according to the JMX spec and we have to extend

The Service Implementation

public class TestService extends ServiceMBeanSupport implements TestServiceMBean {

 // The lifecycle methods
   protected void startService() throws Exception
      System.out.print(“Starting Service”);   }

   protected void stopService() throws Exception
   {“Stoping Service”);

//our management interface method implementation
public String getServiceName(){
 return “TestService”;

To Create a new implementation class, TestService that implements TestServiceMBean.
As advised by the standard MBean specs in Jboss, the implemented class must have the same name as the MBean interface minus the “MBean” suffix. Now we have created the service component, its time to package and deploy the component.



The deployment descriptor (jboss-service.xml)

<?xml version=”1.0″ encoding=”UTF-8″?>

  <mbean code=”TestService” name=”default.test:service= TestService “></mbean>

Now copy the jboss-sevice.xml  inside the META-INF folder.

Now create a SAR for your service

To create the sar file, just bundle all the files(similar like JAR file) with the following structure:


Once all done, copy the SAR into jboss-home/server/default/deploy, And start the Jboss server, you will notice in the initialization of the service in the console with printed message(“Starting Service”).

Happy learning!! 🙂

R Vashi

2 thoughts on “Deploying Service Archive on Jboss Server (SAR) for startup service

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.