Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
92 lines (64 sloc) 4.58 KB

JBoss Modular Service Container ServiceActivator

This project contains a JBoss MSC ServiceActivator that registers a simple MSC service. The intention of this is to demonstrate the ability to add a custom service to JBoss AS7. The use case could be that a similar service was used with an older version of JBoss AS and needs to be migrated.

This example also shows how you can customize logging. See the Custom Logging section for details.

What to look for in this example


This is the file that AS7 will scan for and call the activate method of the fully qualified class name that it finds in this file.


StartupActivator is the implementation of org.jboss.msc.service.ServiceActivator which installs a service into the service controller.


SampleService is a MSC service which could either implement the functionality of delegate to a pre-existing class when the start and stop methods are called.


gradle build


Use any of the management interfaces for AS7 to deploy the jar which is available in target/libs


Using CLI:

[standalone@localhost:9999 /] /deployment=service-activator.jar:undeploy
{"outcome" => "success"}

Service using JEE

A service is also added to this example that uses JEE annotations and hence portable. EEService shows the usage of a singleton service that will have its method annotated with @PostContruct called upon deployment. An upon undeployment the method annotated with @PreDestroy will be called.

Custom logging

This example ships with a custom log4j configuration. To make logging work we need to add deployment module for log4j so that our service-activator module is separated from the log4j module that ships with AS7. The reason for this is that we need log4j to be initialized with our custom log4j.xml and if we specify a dependency to the module 'org.apache.log4j' it will have been initialized before our module is deployed and our custom configuration will not be considered.

Adding a log4 module to the deployment

For this we need to add a jboss-deployment-structure.xml:


    <module name="" >
            <resource-root path="log4j-1.2.16.jar" />
            <resource-root path="logging"/>
           <module name="javaee.api"/>


Above, we are adding the log4j jar and also the path to our log4j.xml which is in the logging directory of the service-activator.jar. We have also added a dependency to javaee.api since log4j has dependencies to a few packages which are included in that module, for example org/w3c/dom/Node

Finally, we need to specify that our module has a dependency to We do this by adding a Class-Path manifest header:

Class-Path: ''

This is done in build.gradle.

Build and deploy the application and you should see the following in the console:

10:30:16,704 INFO  [] (MSC service thread 1-2) Starting deployment of "service-activator.jar"
10:30:16,755 INFO  [] (MSC service thread 1-3) added javax.persistence.api dependency to service-activator.jar
10:30:16,769 INFO  [] (MSC service thread 1-4) JNDI bindings for session bean named EEService in deployment unit deployment "service-activator.jar" are as follows:


10:30:16,833 INFO  [stdout] (MSC service thread 1-1) [logging/log4j.xml]: se.rl.msc.SampleService start 
10:30:16,835 INFO  [stdout] (MSC service thread 1-3) [logging/log4j.xml]: start  
Jump to Line
Something went wrong with that request. Please try again.