old-www/HOWTO/Enterprise-Java-for-Linux-H...

338 lines
7.3 KiB
HTML

<!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(&quot;EJBTestBean
passivated.&quot;);
}
public void ejbActivate() {
System.out.println(&quot;EJBTestBean
activated.&quot;);
}
public void ejbCreate() {
System.out.println(&quot;EJBTestBean
created.&quot;);
}
public void ejbRemove() {
System.out.println(&quot;EJBTestBean
removed.&quot;);
}
public void setSessionContext() {
System.out.println(&quot;EJBTestBean
context set.&quot;);
mContext = context;
}
public String greet()
{
return &quot;Hello, I'm an EJB!&quot;;
}
}
</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>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;Cp1252&quot;?&gt;
</PRE>
<PRE>
</PRE>
<PRE>
&lt;ejb-jar ID=&quot;&quot;&gt;
</PRE>
<PRE>
&lt;description&gt;&lt;/description&gt;
</PRE>
<PRE>
&lt;display-name&gt;&lt;/display-name&gt;
</PRE>
<PRE>
&lt;small-icon&gt;&lt;/small-icon&gt;
</PRE>
<PRE>
&lt;large-icon&gt;&lt;/large-icon&gt;
</PRE>
<PRE>
&lt;ejb-client-jar&gt;&lt;/ejb-client-jar&gt;
</PRE>
<PRE>
&lt;enterprise-beans&gt;
</PRE>
<PRE>
&lt;session&gt;
</PRE>
<PRE>
&lt;description&gt;Nextgen bean&lt;/description&gt;
</PRE>
<PRE>
&lt;ejb-name&gt;nextgen.EJBTest&lt;/ejb-name&gt;
</PRE>
<PRE>
&lt;home&gt;EJBTestHome&lt;/home&gt;
</PRE>
<PRE>
&lt;remote&gt;EJBTest&lt;/remote&gt;
</PRE>
<PRE>
&lt;ejb-class&gt;EJBTestBean&lt;/ejb-class&gt;
</PRE>
<PRE>
&lt;session-type&gt;Stateful&lt;/session-type&gt;
</PRE>
<PRE>
&lt;transaction-type&gt;Bean&lt;/transaction-type&gt;
</PRE>
<PRE>
&lt;env-entry&gt;
</PRE>
<PRE>
&lt;description&gt;&lt;/description&gt;
</PRE>
<PRE>
&lt;env-entry-name&gt;&lt;/env-entry-name&gt;
</PRE>
<PRE>
&lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;
</PRE>
<PRE>
&lt;env-entry-value&gt;&lt;/env-entry-value&gt;
</PRE>
<PRE>
&lt;/env-entry&gt;
</PRE>
<PRE>
&lt;resource-ref&gt;
</PRE>
<PRE>
&lt;description&gt;&lt;/description&gt;
</PRE>
<PRE>
&lt;res-ref-name&gt;&lt;/res-ref-name&gt;
</PRE>
<PRE>
&lt;res-type&gt;&lt;/res-type&gt;
</PRE>
<PRE>
&lt;res-auth&gt;Container&lt;/res-auth&gt;
</PRE>
<PRE>
&lt;/resource-ref&gt;
</PRE>
<PRE>
&lt;/session&gt;
</PRE>
<PRE>
&lt;/enterprise-beans&gt;
</PRE>
<PRE>
&lt;assembly-descriptor /&gt;
</PRE>
<PRE>
&lt;/ejb-jar&gt;
</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>