Tag: ejb31

SAR dependency alternate approach using @Singleton in JBossAS7.1.2

Hi,

SAR files are called as Service Archives. The extension of SAR files are *.sar which contains a “META-INF/jboss-service.xml” file, this file describes the custom MBeans which has to be exposed at the time of deployment or JBoss Startup. JBoss’s service archive architecture is based on the JMX and the SAR files which are basically JBoss specific can be deployed in the jboss inorder to publish your MBean based services. At the time of JBoss startup these service archive deployer (SARDeployer) instantiates the JBoss service classes and exposes them as manageable beans through JMX.

In previous release of JBoss 5/6 the SAR provided mbeans dependency could be very easily defined using <depends> tag, as following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<server>
    <mbean code="custom.mbean.MyServerMonitor" name="service.server.monitor:service=MyMonitor">
         <attribute name="Frequency">5000</attribute>
         <depends>jboss.jca:service=DataSourceBinding,name=MySqlDS</depends>
    </mbean>
</server>

@org.jboss.ejb3.annotation.Service and @org.jboss.ejb3.annotation.Management are no longer supported which could be used to define Services. However in JBossAS7 this approach of defining the dependency is not good and you may see following kind of exceptions at the time of server startup:

JBAS014775:    New missing/unsatisfied dependencies:
      service jboss.mbean.service."jboss.as:subsystem=datasources,data-source=MySqlDS".create (missing) dependents: [service jboss.mbean.service."service.server.monitor:service=MyMonitor".create]
      service jboss.mbean.service."jboss.as:subsystem=datasources,data-source=MySqlDS".start (missing) dependents: [service jboss.mbean.service."service.server.monitor:service=MyMonitor".start]

JBossAS7 is fully EE6 certified application server and it provides a much better approach to create a Service with the help of EJB3.1 specific “javax.ejb.Startup” and “javax.ejb.Singleton” annotations. This kind of service can be made dependent to other services like DataSource. In this example we will see What is the better approach to define a service (without using container specific SAR feature).

The Source code for this demo can be found in the following github link:
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/SingletonServiceDemo

Creating DataSource in JBossAS7.1.2

As we are going make our Service dependent on a DataSource, sothat we can see how the dependency goes.

Configuration-1). So here first of all we will create a DataSource by running the following CLI script in batch mode. So create a file with name “createDataSource.cli” somewhere in your filesystem like “/home/jaysensharma/SingletonServiceDemo/createDataSource.cli” as following:

deploy  /home/jaysensharma/SingletonServiceDemo/mysql-connector-java-5.1.13-bin.jar

/subsystem=datasources/data-source="MySqlDS":add(jndi-name="java:jboss/datasources/MySqlDS",driver-name="mysql-connector-java-5.1.13-bin.jar",connection-url="jdbc:mysql://localhost:3306/testDB",user-name="root",password="redhat")

Configuration-2). Now start your “$JBOSS_HOME/bin/jboss-cli.sh” script in order to run the above deploy the mysql driver and create DataSource as following:

./jboss-cli.sh -c --controller=10.10.10.10:9999 --file=/home/jaysensharma/SingletonServiceDemo/createDataSource.cli

Configuration-3). As soon as you will run the cli script as mentioned above you will see that the following kind of datasource is created on your standalone*.xml.

                <datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS">
                    <connection-url>jdbc:mysql://localhost:3306/testDB</connection-url>
                    <driver>mysql-connector-java-5.1.13-bin.jar</driver>
                    <security>
                        <user-name>root</user-name>
                        <password>redhat</password>
                    </security>
                </datasource>

Creating @Singleton service dependent on the DataSource

Step1). First of all we will create a directory somewhere in our file system as “/home/jaysensharma/SingletonServiceDemo” and then we will create a directory with name “src” inside “/home/jaysensharma/SingletonServiceDemo”:

Step2). Now write a @Startup @Singleton EJB3.1 service using “SingletonServiceBean.java” inside “/home/jaysensharma/SingletonServiceDemo/src” as following:

package sar.dependency.alternative;
import javax.ejb.Startup;
import javax.ejb.Singleton;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

//commons logging
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

// DataSource related
import javax.sql.DataSource;
import java.sql.Connection;

// Resource Injection related
import javax.annotation.Resource;

@Startup
@Singleton  

public class SingletonServiceBean
 {
     private static Log logger = LogFactory.getLog(SingletonServiceBean.class);
     Connection con=null;

     public SingletonServiceBean()
            {
               logger.info("SingletonServiceBean constructor invoked.");
            }

     @Resource(name = "java:jboss/datasources/MySqlDS")
     DataSource ds;
     /* This @PostConstruct annotation is required to tell JBoss to invoke the "performOperations" immediately after the "SingletonServiceBean" creation. */
     @PostConstruct
     public void performOperations()
	    {
               logger.info("SingletonServiceBean performOperations() invoked.");
               try{
                     con=ds.getConnection();
                     logger.info("***** DataSource = "+ds+" . Connection con = "+con+" retrieved from the ConnectionPool.*****");
                  }
               catch(Exception e)
                 {
                     logger.error("Unable to get Connection From DataSource = "+ds+" ERROR: "+e.getMessage());
                     e.printStackTrace();
                 }
	    }

	@PreDestroy
	public void cleanUp() throws Exception {
	  logger.info("cleaning up connections.");
          if(con!=null)
            {
               try{
                     con.close();
                     logger.info("Connection con = "+con+" is successfully returned to the ConnectionPool.");
                  }
               catch(Exception e)
                 {
                     logger.error("Unable to Close Connection con = "+con+" ERROR: "+e.getMessage());
                     e.printStackTrace();
                 }
               finally{
                        try{   con.close(); }
                        catch(Exception ee) { ee.printStackTrace(); }
                      }
            }
	}
 }

Step3). Now the most important part of building / deploying the Singleton Service which we created, so in order to achieve that we will create a simple ant build script, So Create a “build.xml” file inside the “/home/jaysensharma/SingletonServiceDemo” directory as following:

<project name="SingletonStartupService" default="all">
<property name="jboss.home" value="/home/jaysensharma/jboss-as-7.1.2.Final" />
<property name="jboss.module.dir" value="${jboss.home}/modules" />
<property name="basedir" value="." />
<property name="tmp.dir" value="tmp" />
<property name="src.dir" value="src" />
<property name="output.dir" value="build" />
<property name="ear.name" value="TestSingletonService.ear" />
<property name="ejb.jar" value="singletonServiceEJB.jar" />

        <path id="jboss.classpath">
           <fileset dir="${jboss.module.dir}">
               <include name="**/*.jar"/>
           </fileset>
        </path>

        <target name="all" depends="deploy" />

        <target name="build_ear">
           <delete dir="${tmp.dir}" />
           <mkdir dir="${tmp.dir}" />
           <javac srcdir="${src.dir}" destdir="${tmp.dir}"  includes="*.java" classpathref="jboss.classpath"/>

           <jar jarfile="${tmp.dir}/${ejb.jar}" basedir="${tmp.dir}" compress="true" />

           <delete includeEmptyDirs="true">
              <fileset dir="${tmp.dir}/sar"/>
           </delete>
           <mkdir dir="${tmp.dir}/META-INF"/>
           <copy todir="${tmp.dir}/META-INF">
                <fileset dir="${src.dir}/">
                  <include name="application.xml"/>
                </fileset>
           </copy>
           <jar jarfile="${tmp.dir}/${ear.name}" basedir="${tmp.dir}" compress="true" />
           <delete includeEmptyDirs="true">
              <fileset dir="${tmp.dir}/META-INF"/>
           </delete>
           <delete file="${tmp.dir}/${ejb.jar}"/>

           <copy file="${tmp.dir}/${ear.name}" tofile="${output.dir}/${ear.name}"/>
           <delete dir="${tmp.dir}"/>
        </target>

        <target name="deploy" depends="build_ear">
            <echo message="*******************  Deploying the EAR file ${ear.name} *********************" />
            <echo message="********** ${output.dir}/${ear.name} to ${jboss.home}/standalone/deployments **********" />
            <copy todir="${jboss.home}/standalone/deployments/">
                <fileset dir="${output.dir}/">
                  <include name="${ear.name}"/>
                </fileset>
            </copy>
            <echo message="*******************  Deployed Successfully   *********************" />
        </target>

</project>

NOTE: The only change in the above file you need to do is to change the “jboss.home” directory path in the second line of the above script to point to your own JBoss AS7 directory.

Step-4). Now before running your ANT script to build and deploy the above webapplication you should have the ANT as well as JAVA set in the $PATH variable of the Shell / command prompt as following:

For Unix Based OS:
export PATH=/home/jaysensharma/jdk1.6.0_21/bin:/home/jaysensharma/org.apache.ant_1.6.5/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;C:/org.apache.ant_1.6.5/bin;%PATH%

Step-5). Now once the PATH is set In the command/Shell prompt you can move inside the directory “/home/jaysensharma/SingletonServiceDemo” and then run the ant to build and deploy the EJB based EAR applicationon your JBoss Standalone full profile, by running the command “ant deploy”

[jaysensharma@localhost SingletonServiceDemo]$ ant
Buildfile: build.xml

build_ear:
    [mkdir] Created dir: /home/jaysensharma/SingletonServiceDemo/tmp
    [javac] Compiling 1 source file to /home/jaysensharma/SingletonServiceDemo/tmp
      [jar] Building jar: /home/jaysensharma/SingletonServiceDemo/tmp/singletonServiceEJB.jar
    [mkdir] Created dir: /home/jaysensharma/SingletonServiceDemo/tmp/META-INF
      [jar] Building jar: /home/jaysensharma/SingletonServiceDemo/tmp/TestSingletonService.ear
   [delete] Deleting: /home/jaysensharma/SingletonServiceDemo/tmp/singletonServiceEJB.jar
     [copy] Copying 1 file to /home/jaysensharma/SingletonServiceDemo/build
   [delete] Deleting directory /home/jaysensharma/SingletonServiceDemo/tmp

deploy:
     [echo] *******************  Deploying the EAR file TestSingletonService.ear *********************
     [echo] ********** build/TestSingletonService.ear to /home/jaysensharma/jboss-as-7.1.2.Final/standalone/deployments **********
     [copy] Copying 1 file to /home/jaysensharma/jboss-as-7.1.2.Final/standalone/deployments
     [echo] *******************  Deployed Successfully   *********************

all:

BUILD SUCCESSFUL
Total time: 1 second

Step-6). As the application is deployed on your JBoss so now try restarting your JBoss and then see whether the Above service us successfully get the DataSource and JDBC Connection or not. If the Dependency is correctly working then after restarting your JBoss you will see the following kind of message on your JBoss console / logs.

22:41:51,569 INFO  [sar.dependency.alternative.SingletonServiceBean] (MSC service thread 1-1) ***** DataSource = org.jboss.jca.adapters.jdbc.WrapperDataSource@43877c42 . Connection con = org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@5424bf0 retrieved from the ConnectionPool.*****

.
.
Thanks
MiddlewareMagic Team :)


EJB Specific Deployment descriptors in WebLogic and JBoss

Hi,

An EJB container is the component that manages a particular class of EJB. In JBoss there is one instance of the org.jboss.ejb.Container created for each unique configuration of an EJB that is deployed. The actual object that is instantiated is a subclass of Container and the creation of the container instance is managed by the EJBDeployer MBean.

The JBoss EJB container architecture employs a modular plug-in approach. All key aspects of the EJB container may be replaced by custom versions of a plug-in and/or an interceptor by a developer. This approach allows for fine tuned customization of the EJB container behavior to optimally suite your needs. Most of the EJB container behavior is configurable through the EJB JAR META-INF/jboss.xml descriptor and the default server-wide equivalent standardjboss.xml descriptor.

In order to migrate the EJB based application from WebLogic to JBoss most of the peoplefaces challenges specially when it comes to the container specific deployment descriptors. So here in this example we will see what kind of entries goes inside the WebLogic specific EJB Deployment descriptor “weblogic-ejb-jar.xml” and how those parameter and configurations can be moved insside the JBoss specific EJB Deployment descriptors like “jboss.xml” (for JBoss AS4/5/6) and “jboss-ejb3.xml” (for JBoss AS7).

First of all we will see where to find the XSDs based on which we can write these JBoss specific deployment descriptors.

WebLogic XSDs

WebLogic Schemas are present inside : “${WLS_INSTALLATION}/modules/com.bea.core.descriptor.wl.binding_1.2.0.0.jar” file.

Location: “WLS1031/modules/com.bea.core.descriptor.wl.binding_1.2.0.0/META-INF/schemas/weblogic-ejb-jar.xsd”

JBoss XSDs

JBoss Schemas are present inside the ${JBOSS_HOME}/docs/schema/jboss_5_1.xsd (JBoss AS6 and earlier versions)

JBoss Schemas are present inside the ${JBOSS_HOME}/docs/schema/jboss-ejb3-2_0.xsd (JBoss AS7)

Here we will see with all the possible elements inside “weblogic-ejb-jar.xml” file how it looks :

Before Migration (weblogic-ejb-jar.xml)

<weblogic-ejb-jar id="{someID}" version="{someString}">
  <description>{someDescription}</description>
  <weblogic-enterprise-bean id="{someID}">
    <ejb-name>{someEjbName}</ejb-name>
    <transaction-descriptor id="{someID}">
      <trans-timeout-seconds>{someTxTimeout}</trans-timeout-seconds>
    </transaction-descriptor>
    <iiop-security-descriptor id="{someID}">
      <transport-requirements id="{someID}">
        <integrity id="{someID}">{someString}</integrity>
        <confidentiality id="{someID}">{someString}</confidentiality>
        <client-cert-authentication id="{someID}">{someString}</client-cert-authentication>
      </transport-requirements>
      <client-authentication id="{someID}">{someString}</client-authentication>
      <identity-assertion id="{someID}">{someString}</identity-assertion>
    </iiop-security-descriptor>
    <enable-call-by-reference>{some-true-false}</enable-call-by-reference>
    <network-access-point>{someString}</network-access-point>
    <clients-on-same-server>{some-true-false}</clients-on-same-server>
    <run-as-principal-name>{some-Role-Name}</run-as-principal-name>
    <create-as-principal-name id="{someID}">{someString}</create-as-principal-name>
    <remove-as-principal-name id="{someID}">{someString}</remove-as-principal-name>
    <passivate-as-principal-name id="{someID}">{someString}</passivate-as-principal-name>
    <jndi-name>{someJndiName}</jndi-name>
    <local-jndi-name>{someJndiName}</local-jndi-name>
    <dispatch-policy>{some-dispatch-policyType}</dispatch-policy>
    <remote-client-timeout>{someTxTimeout}</remote-client-timeout>
    <stick-to-first-server>{some-true-false}</stick-to-first-server>
  </weblogic-enterprise-bean>
  <security-role-assignment>{some-Role-Name}</security-role-assignment>
  <run-as-role-assignment>{some-Role-Name}</run-as-role-assignment>
  <security-permission>{some-security-permissionType}</security-permission>
  <transaction-isolation id="{someID}">
    <isolation-level id="{someID}">{someString}</isolation-level>
    <method id="{someID}">
      <description>{someDescription}</description>
      <ejb-name>{someEjbName}</ejb-name>
      <method-intf>{something}</method-intf>
      <method-name>{something}</method-name>
      <method-params>{something}</method-params>
    </method>
  </transaction-isolation>

  <message-destination-descriptor>{some-message-destination-descriptorType}</message-destination-descriptor>
  <idempotent-methods id="{someID}">
    <method id="{someID}">
      <description>{someDescription}</description>
      <ejb-name>{someEjbName}</ejb-name>
      <method-intf>{something}</method-intf>
      <method-name>{something}</method-name>
      <method-params>{something}</method-params>
    </method>
  </idempotent-methods>
  <retry-methods-on-rollback id="{someID}">
    <description>{someDescription}</description>
    <retry-count>{someTxTimeout}</retry-count>
    <method id="{someID}">
      <description>{someDescription}</description>
      <ejb-name>{someEjbName}</ejb-name>
      <method-intf>{something}</method-intf>
      <method-name>{something}</method-name>
      <method-params>{something}</method-params>
    </method>
  </retry-methods-on-rollback>
  <enable-bean-class-redeploy>{some-true-false}</enable-bean-class-redeploy>
  <timer-implementation id="{someID}">{someString}</timer-implementation>
  <disable-warning id="{someID}">{someString}</disable-warning>
  <work-manager>{something}</work-manager>
  <component-factory-class-name>{someString}</component-factory-class-name>
  <weblogic-compatibility id="{someID}">
    <entity-always-uses-transaction>{some-true-false}</entity-always-uses-transaction>
  </weblogic-compatibility>
</weblogic-ejb-jar>

After Migration (jboss.xml) to JBoss AS5/6

Now if we will try to migrate a weblogic based EJB Application to JBoss AS 5/6 then it will look something like following:

<jboss version="{someString}" metadata-complete="{true-false}" id="{someID}">
  <loader-repository>{someClassLoaderRepositoryName}</loader-repository>
  <jmx-name>{someJMXName}</jmx-name>
  <security-domain>{someSecurityDomainName}</security-domain>
  <missing-method-permissions-excluded-mode></missing-method-permissions-excluded-mode>
  <unauthenticated-principal></unauthenticated-principal>
  <jndi-binding-policy>{someStringJndiPolicy}</jndi-binding-policy>
  <jacc-context-id></jacc-context-id>
  <webservices id="{someID}">
    <context-root>{someStringValue}</context-root>
    <webservice-description>{some-webservice-descriptionType}</webservice-description>
  </webservices>
  <enterprise-beans>
  <service id="{someID}">
    <ejb-name>{someEJBName}</ejb-name>
    <mapped-name>{someMBeanObjectName}</mapped-name>
    <business-local>{someRemoteInterfaceEJBClass}</business-local>
    <business-remote>{someRemoteInterfaceEJBClass}</business-remote>
    <ejb-class>{someEJBClass}</ejb-class>
    <security-identity id="{someID}">
      <description>{someStringDescription}</description>
      <run-as-principal>{someRoleName}</run-as-principal>
    </security-identity>
    <object-name>{someJMXName}</object-name>
    <management></management>
    <xmbean></xmbean>
    <local-binding>
      <description>{someStringDescription}</description>
      <jndi-name>{someStringJndiPType}</jndi-name>
    </local-binding>
    <remote-binding id="{someID}">
      <description>{someStringDescription}</description>
      <jndi-name>{someStringJndiPType}</jndi-name>
      <client-bind-url></client-bind-url>
      <interceptor-stack></interceptor-stack>
      <proxy-factory></proxy-factory>
      <invoker-name></invoker-name>
    </remote-binding>
    <jndi-name>{someStringJndiPType}</jndi-name>
    <home-jndi-name>{someStringJndiPType}</home-jndi-name>
    <local-jndi-name>{someStringJndiPType}</local-jndi-name>
    <jndi-binding-policy>{someStringJndiPolicy}</jndi-binding-policy>
    <clustered></clustered>
    <cluster-config id="{someID}">
      <description>{someStringDescription}</description>
      <partition-name></partition-name>
      <home-load-balance-policy></home-load-balance-policy>
      <session-state-manager-jndi-name>{someStringValue}</session-state-manager-jndi-name>
    </cluster-config>
    <security-domain>{someMBeanObjectName}</security-domain>
    <method-attributes id="{someID}">
      <method id="{someID}">
        <method-name>{some-method-nameType}</method-name>
        <read-only>{some-boolean}</read-only>
        <idempotent>{some-boolean}</idempotent>
        <transaction-timeout></transaction-timeout>
      </method>
    </method-attributes>
    <depends>{someMBeanObjectName}</depends>
    <annotation id="{someID}">
      <description>{someStringDescription}</description>
      <annotation-class></annotation-class>
      <annotation-implementation-class></annotation-implementation-class>
      <injection-target>{someInjectionTarget}</injection-target>
      <property id="{someID}">
        <description>{someStringDescription}</description>
        <property-name>{someStringValue}</property-name>
        <property-value>{someStringValue}</property-value>
      </property>
    </annotation>
    <ignore-dependency id="{someID}">
      <description>{someStringDescription}</description>
      <injection-target>{someInjectionTarget}</injection-target>
    </ignore-dependency>
    <aop-domain-name></aop-domain-name>
    <pool-config>
      <pool-value></pool-value>
      <pool-max-size></pool-max-size>
      <pool-timeout></pool-timeout>
    </pool-config>
    <concurrent></concurrent>
    <jndi-ref id="{someID}">
      <description>{someStringDescription}</description>
      <jndi-ref-name>{someStringJndiPType}</jndi-ref-name>
    </jndi-ref>
    <port-component id="{someID}">
      <port-component-name>{someStringValue}</port-component-name>
      <port-component-uri>{someStringValue}</port-component-uri>
      <auth-method>{someStringValue}</auth-method>
      <transport-guarantee>{someStringValue}</transport-guarantee>
      <secure-wsdl-access>{some-boolean}</secure-wsdl-access>
    </port-component>
    <ejb-timeout-identity id="{someID}">
      <description>{someStringDescription}</description>
      <run-as-principal>{someRoleName}</run-as-principal>
    </ejb-timeout-identity>
  </service>
  </enterprise-beans>
  <assembly-descriptor id="{someID}">
    <security-role>{some-security-roleType}</security-role>
    <message-destination>{some-message-destinationType}</message-destination>
  </assembly-descriptor>
  <resource-managers id="{someID}">
    <description>{someStringDescription}</description>
    <resource-manager id="{someID}" res-class="{someStringValue}">
      <description>{someStringDescription}</description>
      <res-name>{someMBeanObjectName}</res-name>
    </resource-manager>
  </resource-managers>
</jboss>

So now as we know the tags which we can use in an order while migrating from WebLogic to JBoss, it will be an easy task now. :)
To know more about these common JBoss specific deployment descriptors please refer to the following link:
http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/ENC_Usage_Conventions-EJB_References_with_jboss.xml_and_jboss_web.xml.html
.
.
Thanks :)
Middleware Magic Team


EJB3.1 Automatic Schedulers in JBoss AS7

Hi,

Job Scheduling is one of the most important in while working in admin profile or for the developers. There were various options available for job scheduling, but as this has become a most findamental requirement for most of the applications or admins, So now as part of EE6 we can crate our own Automatic Schedulers/timers using the annotation “javax.ejb.Schedule”.

Enterprise bean timers are either programmatic timers or automatic timers. In this example we will see how we can create an “Automatic Timer”, Timers can be set according to a calendar-based schedule and these are very easy to maintain. Schedule a timer for automatic creation with a timeout schedule based on a cron-like time expression. The annotated method is used as the timeout callback method. All elements of this annotation are optional. If none are specified a persistent timer will be created with callbacks occuring every day at midnight in the default time zone associated with the container in which the application is executing. For more information on this you can refer to the following link:
http://docs.oracle.com/javaee/6/api/javax/ejb/Schedule.html

Step1). Create a Directory somewhere inside your file system where we can create our web application. Suppose i am creating a directory as “/home/userone/EJB31_Automatic_Scheduler” and the create a subdirectory with name “src” inside “/home/userone/EJB31_Automatic_Scheduler”

Step2). Now we will write the Scheduler Bean “AutomaticSchedulerBean.java” program inside the “/home/userone/EJB31_Automatic_Scheduler/src” directory which will have a method “backgroundProcessing()” and it will run on scheduled time as mentioned below:

dayOfWeek=* means all the seven days of a week
hour = “*” means every hour of a day
minute = “*” means every minute
second=”*/5″ means every five second interval
year=”2012″ means in the year 2012

package test;
import javax.ejb.Stateless;
import java.util.Date;
import javax.ejb.Schedule;

@Stateless(name="AutomaticSchedulerBean")
public class AutomaticSchedulerBean
 {
     @Schedule(dayOfWeek = "*", hour = "*", minute = "*", second = "*/5",year="2012", persistent = false)
     public void backgroundProcessing()
	    {
		   System.out.println("\n\n\t AutomaticSchedulerBean's backgroundProcessing() called....at: "+new Date());
	    }
 }

Step3). Now we will write a simple ant “build.xml” file in order to build the scheduler JAR and deploy it on JBoss AS7. So write the following “build.xml” file inside “/home/userone/EJB31_Automatic_Scheduler” as following:

<project name="Secured EJB Remote" default="all">
<property name="jboss.home" value="/home/userone/jboss-as-7.1.0.CR1b" />
<property name="jboss.module.dir" value="${jboss.home}/modules" />
<property name="basedir" value="." />
<property name="tmp.dir" value="tmp" />
<property name="src.dir" value="src" />
<property name="output.dir" value="build" />
<property name="ejb.jar" value="schedulerEJB.jar" />

        <path id="jboss.classpath">
           <fileset dir="${jboss.module.dir}">
               <include name="**/*.jar"/>
           </fileset>
        </path>

        <target name="all" depends="deploy" />

        <target name="build_ejb_jar">
           <delete dir="${output.dir}" />
           <delete dir="${tmp.dir}" />
           <mkdir dir="${output.dir}" />
           <mkdir dir="${tmp.dir}" />
           <javac srcdir="${src.dir}" destdir="${tmp.dir}"  includes="*.java" classpathref="jboss.classpath"/> 

           <jar jarfile="${tmp.dir}/${ejb.jar}" basedir="${tmp.dir}" compress="true" />
           <copy file="${tmp.dir}/${ejb.jar}" tofile="${output.dir}/${ejb.jar}"/>

           <delete dir="${tmp.dir}"/>
        </target>

        <target name="deploy" depends="build_ejb_jar">
            <echo message="*******************  Deploying the EAR file ${ear.name} *********************" />
            <echo message="********** ${output.dir}/${ejb.jar} to ${jboss.home}/standalone/deployments **********" />
            <copy todir="${jboss.home}/standalone/deployments/">
                <fileset dir="${output.dir}/">
                  <include name="${ejb.jar}"/>
                </fileset>
            </copy>
            <echo message="*******************  Deployed Successfully   *********************" />
            <echo message="******************* Check JBoss AS7 Console  *********************" />
        </target>

</project>

NOTE: The only change in the above file you need to do is to change the “jboss.home” directory path in the second line of the above script is to point to your own JBoss AS7 directory home directory.

Step4). Now before running your ANT script to build and deploy the above webapplication you should have the ANT as well as JAVA set in the $PATH variable of the Shell / command prompt as following:

For Unix Based OS:
export PATH=/home/userone/jdk1.6.0_21/bin:/home/userone/apache-ant-1.8.2/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;C:/apache-ant-1.8.2/bin;%PATH%

Step5). Now run the ant file from the directory where you have placed the “build.xml” file as following:

[userone@localhost EJB31_Automatic_Scheduler]$ ant
Buildfile: build.xml

build_ejb_jar:
   [delete] Deleting directory /home/userone/EJB31_Automatic_Scheduler/build
    [mkdir] Created dir: /home/userone/EJB31_Automatic_Scheduler/build
    [mkdir] Created dir: /home/userone/EJB31_Automatic_Scheduler/tmp
    [javac] Compiling 1 source file to /home/userone/EJB31_Automatic_Scheduler/tmp
      [jar] Building jar: /home/userone/EJB31_Automatic_Scheduler/tmp/schedulerEJB.jar
     [copy] Copying 1 file to /home/userone/EJB31_Automatic_Scheduler/build
   [delete] Deleting directory /home/userone/EJB31_Automatic_Scheduler/tmp

deploy:
     [echo] *******************  Deploying the EAR file ${ear.name} *********************
     [echo] ********** build/schedulerEJB.jar to /home/userone/jboss-as-7.1.0.CR1b/standalone/deployments **********
     [copy] Copying 1 file to /home/userone/jboss-as-7.1.0.CR1b/standalone/deployments
     [echo] *******************  Deployed Successfully   *********************
     [echo] ******************* Check JBoss AS7 Console  *********************

all:

BUILD SUCCESSFUL
Total time: 4 seconds

Step6). Now as soon the above Scheduler is deployed on the JBoss AS7 we will see this kind of messages in the JBoss AS7 Console.

15:14:33,655 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) Starting deployment of "schedulerEJB.jar"
15:14:34,085 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-5) JNDI bindings for session bean named AutomaticSchedulerBean in deployment unit deployment "schedulerEJB.jar" are as follows:

	java:global/schedulerEJB/AutomaticSchedulerBean!test.AutomaticSchedulerBean
	java:app/schedulerEJB/AutomaticSchedulerBean!test.AutomaticSchedulerBean
	java:module/AutomaticSchedulerBean!test.AutomaticSchedulerBean
	java:global/schedulerEJB/AutomaticSchedulerBean
	java:app/schedulerEJB/AutomaticSchedulerBean
	java:module/AutomaticSchedulerBean

15:14:34,477 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "schedulerEJB.jar"
15:14:35,014 INFO  [stdout] (pool-9-thread-1)
15:14:35,015 INFO  [stdout] (pool-9-thread-1)
15:14:35,015 INFO  [stdout] (pool-9-thread-1) 	 AutomaticSchedulerBean's backgroundProcessing() called....at: Sun Jan 29 15:14:35 IST 2012
15:14:40,015 INFO  [stdout] (pool-9-thread-2)
15:14:40,015 INFO  [stdout] (pool-9-thread-2)
15:14:40,015 INFO  [stdout] (pool-9-thread-2) 	 AutomaticSchedulerBean's backgroundProcessing() called....at: Sun Jan 29 15:14:40 IST 2012
15:14:45,003 INFO  [stdout] (pool-9-thread-3)
15:14:45,003 INFO  [stdout] (pool-9-thread-3)
15:14:45,003 INFO  [stdout] (pool-9-thread-3) 	 AutomaticSchedulerBean's backgroundProcessing() called....at: Sun Jan 29 15:14:45 IST 2012
15:14:50,003 INFO  [stdout] (pool-9-thread-4)
15:14:50,003 INFO  [stdout] (pool-9-thread-4)
15:14:50,003 INFO  [stdout] (pool-9-thread-4) 	 AutomaticSchedulerBean's backgroundProcessing() called....at: Sun Jan 29 15:14:50 IST 2012

These timers are good to perform some background activities like cleaning up some logs …etc.
.
.
Thanks
MiddlewareMagic Team


  • Receive FREE Updates


    FREE Email updates of our new posts Enter your email address:



  • Magic Archives

  • Copyright © 2010-2012 Middleware Magic. All rights reserved. | Disclaimer