<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML> <HEAD> <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9"> <TITLE>Enterprise Java for Linux HOWTO: How to Setup Enterprise Java Bean (EJB) Support </TITLE> <LINK HREF="Enterprise-Java-for-Linux-HOWTO-6.html" REL=previous> <LINK HREF="Enterprise-Java-for-Linux-HOWTO.html#toc7" REL=contents> </HEAD> <BODY> Next <A HREF="Enterprise-Java-for-Linux-HOWTO-6.html">Previous</A> <A HREF="Enterprise-Java-for-Linux-HOWTO.html#toc7">Contents</A> <HR> <H2><A NAME="sec: ejb"></A> <A NAME="s7">7. How to Setup Enterprise Java Bean (EJB) Support </A></H2> <P> <P>To be written. <H2><A NAME="sec: weblogic"></A> <A NAME="ss7.1">7.1 BEA WebLogic </A> </H2> <P> <P>To be written. <P>See <A HREF="http://www.beasys.com/linux/">http://www.beasys.com/linux/</A>for more information. <P> <H2><A NAME="sec: ejboss"></A> <A NAME="ss7.2">7.2 EJBoss</A> </H2> <P> <H3>Background</H3> <P>EJBoss has been renamed JBoss and is well advanced with stable J2EE compliant releases at <A HREF="http://www.jboss.org/">http://www.jboss.org/</A>. <P>This section was written when it was still EJBoss 0.95 and needs to be updated. <P> <H3>Download</H3> <P> <P>JBoss can be downloaded from the JBoss website at <A HREF="http://www.jboss.org/">http://www.jboss.org/</A>. <P> <H3>Installation</H3> <P> <P>I suggest installing files in the /usr/local directory. After downloading, run: <PRE> mkdir /usr/local/ejboss mv ejboss* /usr/local/ejboss </PRE> <P>Unjar the file: <PRE> jar xvf ejboss095_jdk122.jar </PRE> <P>You should see various files and directories created under /usr/local/ejboss. <P>The above example shows EJBoss 0.95 for JDK 1.2.2. Substitute the file names as appropriate. <H3>Setting up Your Environment</H3> <P> <P>The environment variables to set up are: <UL> <LI>CLASSPATH</LI> </UL> <P>The CLASSPATH environment variable references all JARs and directories that you will need to compile and run Java programs. <P>Include the EJBoss JAR and the beans/generated directory in your CLASSPATH. <PRE> export CLASSPATH=/usr/local/ejboss/lib/ejboss095_jdk122.jar:/usr/local/ejboss/beans/generated:$CLASSPATH </PRE> <H3>Confiming Your Installation</H3> <P> <P>You are now ready to compile and run a simple EJB application. Create the following three source files for the server. <P>First, the business interface. <PRE> // EJBTest.java import javax.ejb.*; import java.rmi.RemoteException; public interface EJBTest extends EJBObject { public String greet() throws RemoteException; } </PRE> <P>Second, the home interface. <PRE> // EJBTestHome.java import javax.ejb.*; import java.rmi.RemoteException; public interface EJBTestHome extends EJBHome { public EJBTest create() throws CreateException, RemoteException; } </PRE> <P>Third, the bean implementation class. <PRE> // 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!"; } } </PRE> <P>Compile the server source files with the Java compiler: <PRE> javac EJBTest*.java </PRE> <P>If the compiler produces errors, double check the syntax and confirm your PATH and CLASSPATH. <P>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. <P>First, create the file ejb-jar.xml. <PRE> <?xml version="1.0" encoding="Cp1252"?> </PRE> <PRE> </PRE> <PRE> <ejb-jar ID=""> </PRE> <PRE> <description></description> </PRE> <PRE> <display-name></display-name> </PRE> <PRE> <small-icon></small-icon> </PRE> <PRE> <large-icon></large-icon> </PRE> <PRE> <ejb-client-jar></ejb-client-jar> </PRE> <PRE> <enterprise-beans> </PRE> <PRE> <session> </PRE> <PRE> <description>Nextgen bean</description> </PRE> <PRE> <ejb-name>nextgen.EJBTest</ejb-name> </PRE> <PRE> <home>EJBTestHome</home> </PRE> <PRE> <remote>EJBTest</remote> </PRE> <PRE> <ejb-class>EJBTestBean</ejb-class> </PRE> <PRE> <session-type>Stateful</session-type> </PRE> <PRE> <transaction-type>Bean</transaction-type> </PRE> <PRE> <env-entry> </PRE> <PRE> <description></description> </PRE> <PRE> <env-entry-name></env-entry-name> </PRE> <PRE> <env-entry-type>java.lang.String</env-entry-type> </PRE> <PRE> <env-entry-value></env-entry-value> </PRE> <PRE> </env-entry> </PRE> <PRE> <resource-ref> </PRE> <PRE> <description></description> </PRE> <PRE> <res-ref-name></res-ref-name> </PRE> <PRE> <res-type></res-type> </PRE> <PRE> <res-auth>Container</res-auth> </PRE> <PRE> </resource-ref> </PRE> <PRE> </session> </PRE> <PRE> </enterprise-beans> </PRE> <PRE> <assembly-descriptor /> </PRE> <PRE> </ejb-jar> </PRE> <P>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. <P>Second, relative to the directory of the three class files you just created, create a META-INF directory. <PRE> mkdir META-INF mv ejb-jar.xml META-INF </PRE> <P>Third, package all four files into a jar. <PRE> jar cvf EJBTest.jar EJBTest*.class META-INF/ejb-jar.xml </PRE> <P>You should see that it added the manifest as well as the three class files and the XML deployment descriptor file. <P>Fourth, put the JAR you just created in the EJBoss beans directory. <PRE> mv EJBTest.jar /usr/local/ejboss/beans </PRE> <P>Fifth, move the class files you created to the EJBoss beans/generated directory. <PRE> mv EJBTest*.class /usr/local/ejboss/beans/generated </PRE> <P>(This fifth step is redudant due to a bug in EJBoss 0.95. ) <P>You are now ready to start the EJBoss server. <P>cd /usr/local/ejboss <P>sh server.sh <P>You should see the proxy files compile automatically and confirmation that your EJB is deployed. <P>You are now ready to write, compile and test the simple client applicaiton. <H2><A NAME="sec: jonas"></A> <A NAME="ss7.3">7.3 Bullsoft JOnAS EJB </A> </H2> <P> <P>To be written. <P>See <A HREF="http://www.bullsoft.com/ejb/">http://www.bullsoft.com/ejb/</A>for more information. <P> <HR> Next <A HREF="Enterprise-Java-for-Linux-HOWTO-6.html">Previous</A> <A HREF="Enterprise-Java-for-Linux-HOWTO.html#toc7">Contents</A> </BODY> </HTML>