Wednesday, November 18, 2009

MAVEN Deployable Unit PLUGIN





Hi all,
This is another tutorial to develope JAIN SLEE Projects using the Maven-du-plugin.


TOOLS:
Mobicents JAIN SLEE Server 1.2.6-GA - http://sourceforge.net/projects/mobicents/files/

ATTENTION! Some JAIN SLEE programmers recommend using MAVEN DU PLUGIN version 1.0.0.BETA2
RESUME: This tutorial shows how to create a JAIN SLEE project with maven (using maven commands over Windows console). Also we can introduce a Ant code to deploy the resultant Deployable Unit of the project over Mobicents JAIN SLEE Server.
Maven installation:
1. Download Maven binary resource and unzip it.
2. Create a System Variable M2_HOME to the unzipped folder.
3. Modify the PATH system variable adding “;%M2_HOME%\bin”.
JAIN SLEE Server installation
1. Download the JAIN SLEE Server 1.2.6-GA binary resource and unzip it.
2. Create a System variable JBOSS_HOME to the jboss-4.2.3.GA folder.
3. Start the server executing jboss-4.2.3.GA\bin\run.bat
Maven DU Plugin
We use a folder as workspace, in our case we have created a the “C:\MAVEN WORKSPACE” folder, and we have created a folder for the project called “My project”
Create the next folder tree into the project folder:



Required files:
· POM.xml on Project Root folder (“My Project”)
· POM.xml on Project Root folder \du
· POM.xml on Project Root folder\sbb
· Service.xml on Project Root folder\du\src\main\resources\services
· Sbb-jar.xml on Project Root folder\sbb\src\main\resources\META-INF
· Sbb.java on Project Root folder\sbb\src\main\java\“package”
The Root POM.XML describes the name, vendor, and version of the project you want to build with maven. Also it contains a reference of the folders that compose the project and the repositories that are required.
The DU POM.XML creates the DU.jar file and requires the information of:
· The main project that is referenced
· The SBB that contain your project
· The Maven-du-plugin you want to use
· The ant code for autodeploy the DU resultant
The SBB POM.XML requires the information of the main project that composes, and has a description of itself and the dependences that requires de SBBs.
The sbb-jar.xml has the reference of the SBB POM.XML and also contains the path to the sbb.java and the events that implements.
Finally the service.xml has the description of the service (name, vendor and version) and has the reference to the artifact sbb (the same as sbb POM.XML and sbb-jar.xml).





1. Root folder POM.xml












Maven Project
Description of the Maven project
The description of folders that compose the project.
The repository ofthe JAIN SLEE projects.
The repository of the Maven-Du-plugin.





2.DU folder POM.xml




All POM.xml must implement
This is the description of the Base project.
This is the result Deployable Unit file
This is the list of sbb that we want to include on the project
The first plugin defines the MAVEN DU PLUGIN with the version you want to use
The second plugin defines the autodeploy (copy the resultant DU to the deploy folder of jboss). Make sure the path exists and the JBOSS_HOME system variable is configured in your system.
ATTENTION! The sbb dependency must has the same version as described on sbb-jar.xml (change $(pom.version) for 1.0 in this case, because our pom version is 1.0.0 and there is not any sbb vith 1.0.0 version.)


3. SBB folder POM.xml






All POM.xml must implement
This is the description of the Base project.
This is the Sbb description
There are the dependences that our Sbb.java needs




4. Service.xml on Project Root folder\du\src\main\resources\services











Service.xml Structure

This is the description of the JAIN SLEE Service.
This is the list of SBB includes on the JAIN SLEE Service
Priority




5. Sbb-jar.xml on Project Root folder\sbb\src\main\resources\META-INF












SBB-jar Structure
Description of the SBB
The events implemented on the SBB




6. Sbb.java on Project Root folder\sbb\src\main\java\“package”




package org.i2cat.slee.firstSteps.sbb;


import javax.naming.Context;
import javax.naming.InitialContext;
import javax.slee.*;
import javax.slee.serviceactivity.ServiceActivity;
import javax.slee.serviceactivity.ServiceActivityFactory;
import org.apache.log4j.Logger;

public abstract class FirstSbb implements javax.slee.Sbb {

private static Logger logger = Logger.getLogger(FirstSbb.class);
public void onServiceStartedEvent( javax.slee.serviceactivity.ServiceStartedEvent event, ActivityContextInterface aci) {
try {
Context myEnv = (Context) new InitialContext().lookup("java:comp/env");
ServiceActivity sa = ((ServiceActivityFactory) myEnv
.lookup("slee/serviceactivity/factory")).getActivity();
if (sa.equals(aci.getActivity())) {
logger.info("THIS IS A MESSAGE OF HOPE!!!");
}
aci.detach(this.sbbContext.getSbbLocalObject());
} catch (Exception e) {
logger.error("Can't handle service started event.", e);
}
}
public void setSbbContext(SbbContext context) { this.sbbContext = context; }
public void unsetSbbContext() { this.sbbContext = null; }
public void sbbCreate() throws javax.slee.CreateException {}
public void sbbPostCreate() throws javax.slee.CreateException {}
public void sbbActivate() {}
public void sbbPassivate() {}
public void sbbRemove() {}
public void sbbLoad() {}
public void sbbStore() {}
public void sbbExceptionThrown(Exception exception, Object event, ActivityContextInterface activity) {}
public void sbbRolledBack(RolledBackContext context) {}
protected SbbContext getSbbContext() {return sbbContext;}
private SbbContext sbbContext;
}



This code depends on the name of your SBB
This code affects to the folder tree.



In this example we use the same SBB code as the First Steps Tutorial. This SBB is packed into org.i2cat.slee.firstSteps.sbb and then we have to create the next folder tree into the Sbb\src\main\java. Also we have to rename the RootSbb.java to FirstSbb.java as we have described in the SBB-jar.xml in the sbb-classes tag.



7.Installation
Once we have the files and folder tree, we have to start the JAIN SLEE Server. The next step is open a command console, access to MyProject folder, and run: “mvn install”. Now maven will start downloading the dependences (it could take several minutes). When it finish, a Successful message must appear, and JAIN SLEE Server Console must show the Message of hope.
If there is any error in the xmls code, the JAIN SLEE Server console will show a message saying waiting to resolve dependences. You can consult the problem at:

http://localhost:8080/ JMX Console /service=JSLEEDeployer / java.lang.String showStatus()

For more information and help: http://groups.google.com/group/mobicents-public?hl=en