Skip to main content

deployment of ejb under jboss

Jboss deployment of HelloWorld EJB example

  • Deployment under jboss is relatively simple:
  • pack classes and deployment descriptors in jar
  • create ear
  • copy ear into deploy directory of jboss

Then to run the client:

  • create client java file that calls util class of HelloWorld ejb example
  • create client jar with proper jndi.properties
  • call client

To create the jar/ear we need to add the following to our build.xml file:

<!-- =================================================================== -->

<!-- Deployment -->

<!-- =================================================================== -->

<target name="jar" depends="compile">

    <mkdir dir="${samples.jar.dir}" />

    <jar jarfile="${samples.jar.dir}/ejb-hello.jar">

    <fileset dir="${samples.classes.dir}" includes="**" excludes="**/client/**" />

    <metainf dir="${samples.meta-inf.dir}"

        includes="**"

        excludes="application.xml" />

    </jar>

</target>

<target name="ear" depends="jar">

    <mkdir dir="${samples.ear.dir}" />

    <copy file="etc/application.xml" todir="${samples.meta-inf.dir}" />

    <jar jarfile="${samples.ear.dir}/helloworld.ear">

        <fileset dir="${samples.jar.dir}" includes="**/*" excludes="**/client*.jar" />

        <metainf dir="${samples.meta-inf.dir}" includes="application.xml" />

    </jar>

</target>

<target name="deploy-jboss" depends="ear">

    <copy todir="${jboss4.deploy.dir}">

        <fileset dir="${samples.ear.dir}" includes="helloworld.ear" />

    </copy>

</target>

You also need to add some properties to your build-dist.properties file:

jboss4.deploy.dir=/usr/local/jboss-4.0.2/server/default/deploy

jboss4.client.j2ee.jar=/usr/local/jboss-4.0.2/client/jbossall-client.jar

The ear target also uses an application.xml file. This is a general file, and not propiety for jboss. It contains:

<?xml version="1.0" encoding="ISO-8859-1"?>

    <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN'       'http://java.sun.com/j2ee/dtds/application_1_2.dtd'>

    <application>

        <display-name>HelloWorld</display-name>

        <description>J2EE application to helloworld</description>

        <module>

            <ejb>ejb-hello.jar</ejb>

        </module>

    </application>

Ears could also have propiety deployment descriptors, for example when you want to deploy mbeans. However, my example is simple, and does not need it.

Now when you start jboss (jboss 4), and run ant deploy-jboss, you should see a successful deployment.

To make use of the newly deployed EJB, you will need to write a client file:

/**

* $Id$

*/

package com.jankester.tryout.client;


import java.rmi.RemoteException;

import javax.ejb.CreateException;

import javax.naming.NamingException;

import com.jankester.tryout.ejb.session.HelloWorld;

import com.jankester.tryout.ejb.session.HelloWorldHome;

import com.jankester.tryout.ejb.session.HelloWorldUtil;


/**

* @author jkester

*

*/

public class HelloWorldEjb

{


/**

* @param args

*/

    public static void main(String[] args)

    {

        System.out.println("calling client of HelloWorld");

        try

        {

            HelloWorldHome helloHome = HelloWorldUtil.getHome();

            System.out.println("Got HelloWorld home");

            HelloWorld hw = helloHome.create();

            String answer1 = hw.helloWorld();

            String answer2 = hw.helloWorld("It's me again ..");

            System.out.println("answer1=" + answer1 + " answer2=" + answer2);

        }

        catch (NamingException ne)

        {

            System.out.println("Failed getting home: " + ne.getMessage());

            System.out.println("exception=" + ne);

        }

        catch (RemoteException re)

        {

            System.out.println("Failed calling getHome: " + re.getMessage());

        }

        catch (CreateException ce)

        {

            System.out.println("Failed creating HelloWorld proxy: " + ce.getMessage());

        }

    }

}

The client file makes use of the interfaces that have been generated by xdoclet. We will pack all classes into a client-hello.jar.

Further we need to add a jndi.properties file for jboss. It contains:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

java.naming.provider.url=localhost

This file will also be packed into the client-hello.jar. We need to add the following targets to our build.xml:

<target name="client-jar-jboss" depends="compile">

    <mkdir dir="${samples.jar.dir}" />

    <jar jarfile="${samples.jar.dir}/client-hello.jar">

        <fileset dir="${samples.classes.dir}">

            <include name="**/client/**" />

            <include name="**/ejb/**" />

            <exclude name="**/ejb/**/*Local*" />

            <exclude name="**/ejb/**/*Bean*" />

            <exclude name="**/ejb/**/*Session*" />

        </fileset>

        <fileset dir="etc/jboss" includes="*.properties" />

    </jar>

</target>

<target name="helloworld-jboss" depends="client-jar-jboss">

    <java classname="com.jankester.tryout.client.HelloWorldEjb"

        failonerror="yes"

        fork="yes"

        spawn="no">

        <classpath>

            <pathelement location="${samples.jar.dir}/client-hello.jar" />

            <pathelement location="${jboss4.client.j2ee.jar}" />

        </classpath>

    </java>

</target>

Now you can call the client file with “ant helloworld-jboss”. You should see output like this:

[java] calling client of HelloWorld

[java] Got HelloWorld home

[java] answer1=Hello world from HelloWorldBean! answer2=Hello It's me again ..!

Comments

Popular posts from this blog

SSL handshake failed: Secure connection truncated

Got this problem on Ubuntu 9.10 and 10.10. svn co --username=xx https:/yy zz “SSL handshake failed: Secure connection truncated” According to this link bug-ubuntu The solution is: sudo apt-get install libneon27 cd /usr/lib/ sudo rm libneon-gnutls.so.27 sudo ln -s /usr/lib/libneon.so.27 libneon-gnutls.so.27

Junit4 running parallel junit classes

To run junit testcases parallel, you can create your own class to run junit with: Add this tag to your class declaration. @RunWith(Parallelized.class) Implementation of this class looks like: package mypackage; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.junit.runners.Parameterized; import org.junit.runners.model.RunnerScheduler; public class Parallelized extends Parameterized {         private static class ThreadPoolScheduler implements RunnerScheduler     {         private ExecutorService executor;                 public ThreadPoolScheduler()         {             String threads = System.getProperty("junit.parallel.threads", "16");    ...

Create a groovy console and bind to selenium

Required groovy files In the previous posting we defined the pom file that we need for our build environment. Now we will setup some groovy files to get selenium and groovy running interactively. ConsoleWaiter.groovy The idea of Groovy Console I found on some other sides. Honour goes for instance too: http://josefbetancourt.wordpress.com/tag/eclipse-2/ I copied some code of this, and put it under src/test/groovy/com/jankester/selenium/test/utils: package com.jankester.selenium.test.utils /** * File: ConsoleWaiter.groovy */ import groovy.lang.Binding; import groovy.ui.Console; /** * Provides a wrapper for the console. * * Based on source by John Green * Adapted from: http://www.oehive.org/files/ConsoleWaiter.groovy * Released under the Eclipse Public License * http://www.eclipse.org/legal/epl-v10.html * * I added methods to allow use from Java. * * The run() method launches the console and causes this thread * to sleep until the console's window is closed....