Next Previous Contents

7. How to Setup Enterprise Java Bean (EJB) Support

To be written.

7.1 BEA WebLogic

To be written.

See http://www.beasys.com/linux/for more information.

7.2 EJBoss

Background

EJBoss has been renamed JBoss and is well advanced with stable J2EE compliant releases at http://www.jboss.org/.

This section was written when it was still EJBoss 0.95 and needs to be updated.

Download

JBoss can be downloaded from the JBoss website at http://www.jboss.org/.

Installation

I suggest installing files in the /usr/local directory. After downloading, run:

mkdir /usr/local/ejboss 
mv ejboss* /usr/local/ejboss

Unjar the file:

jar xvf ejboss095_jdk122.jar

You should see various files and directories created under /usr/local/ejboss.

The above example shows EJBoss 0.95 for JDK 1.2.2. Substitute the file names as appropriate.

Setting up Your Environment

The environment variables to set up are:

The CLASSPATH environment variable references all JARs and directories that you will need to compile and run Java programs.

Include the EJBoss JAR and the beans/generated directory in your CLASSPATH.

export CLASSPATH=/usr/local/ejboss/lib/ejboss095_jdk122.jar:/usr/local/ejboss/beans/generated:$CLASSPATH

Confiming Your Installation

You are now ready to compile and run a simple EJB application. Create the following three source files for the server.

First, the business interface.

// EJBTest.java

import javax.ejb.*;
import java.rmi.RemoteException;

public
 interface EJBTest extends EJBObject { 
  public String greet() throws
 RemoteException;

}

Second, the home interface.

// EJBTestHome.java

import javax.ejb.*;
import java.rmi.RemoteException;

public
 interface EJBTestHome extends EJBHome {

  public EJBTest create() throws
 
   CreateException, RemoteException;
}

Third, the bean implementation class.

// EJBTestBean.java

import javax.ejb.*;
import java.rmi.RemoteException;

public
 interface EJBTestBean implements SessionBean {

  private SessionContext
 mContext = null;

  public void ejbPassivate() {
    System.out.println("EJBTestBean
 passivated.");
}

  public void ejbActivate() {
    System.out.println("EJBTestBean
 activated.");
}

  public void ejbCreate() {
    System.out.println("EJBTestBean
 created.");
}

  public void ejbRemove() {
    System.out.println("EJBTestBean
 removed.");
}

  public void setSessionContext() {
    System.out.println("EJBTestBean
 context set.");
    mContext = context;
}

  public String greet()
 {
    return "Hello, I'm an EJB!";
}

}

Compile the server source files with the Java compiler:

javac EJBTest*.java

If the compiler produces errors, double check the syntax and confirm your PATH and CLASSPATH.

Now that you have successfully written and compiled the server source files, you need to deploy your bean to EJBoss. Deploying a bean to EJBoss requires several steps that must be performed exactly.

First, create the file ejb-jar.xml.

<?xml version="1.0" encoding="Cp1252"?>
 
<ejb-jar ID="">
     <description></description>
     <display-name></display-name>
     <small-icon></small-icon>
     <large-icon></large-icon>
     <ejb-client-jar></ejb-client-jar>
     <enterprise-beans>
       <session>
         <description>Nextgen bean</description>
         <ejb-name>nextgen.EJBTest</ejb-name>
         <home>EJBTestHome</home>
         <remote>EJBTest</remote>
         <ejb-class>EJBTestBean</ejb-class>
         <session-type>Stateful</session-type>
         <transaction-type>Bean</transaction-type>
         <env-entry>
           <description></description>
           <env-entry-name></env-entry-name>
           <env-entry-type>java.lang.String</env-entry-type>
           <env-entry-value></env-entry-value>
         </env-entry>
         <resource-ref>
           <description></description>
           <res-ref-name></res-ref-name>
           <res-type></res-type>
           <res-auth>Container</res-auth>
         </resource-ref>
       </session>
     </enterprise-beans>
     <assembly-descriptor />
   </ejb-jar>

The above file, which must be named ejb-jar.xml identifies the interface and class names of files that you just created as well as a name for the object.

Second, relative to the directory of the three class files you just created, create a META-INF directory.

mkdir META-INF
mv ejb-jar.xml META-INF

Third, package all four files into a jar.

jar cvf EJBTest.jar EJBTest*.class META-INF/ejb-jar.xml

You should see that it added the manifest as well as the three class files and the XML deployment descriptor file.

Fourth, put the JAR you just created in the EJBoss beans directory.

mv EJBTest.jar /usr/local/ejboss/beans

Fifth, move the class files you created to the EJBoss beans/generated directory.

mv EJBTest*.class /usr/local/ejboss/beans/generated

(This fifth step is redudant due to a bug in EJBoss 0.95. )

You are now ready to start the EJBoss server.

cd /usr/local/ejboss

sh server.sh

You should see the proxy files compile automatically and confirmation that your EJB is deployed.

You are now ready to write, compile and test the simple client applicaiton.

7.3 Bullsoft JOnAS EJB

To be written.

See http://www.bullsoft.com/ejb/for more information.


Next Previous Contents

Hosting by: Hurra Communications Ltd.
Generated: 2007-01-26 17:57:44