<?xml version="1.0"?>

<document name="orion-primer" title="Orion Primer" version="$Revision: 4.41 $" date="$Date: 2001/06/27 10:40:38 $">

   <author name="Ernst de Haan" email="ernst@jollem.com" />

   <contributor name="Alex Chudnovsky"       email="chud@bigpond.net.au" reviewer="true"/>
   <contributor name="Al Fogleson"           email="foglesa@email.uophx.edu" />
   <contributor name="Poririev Sergey"       email="parf@aha.ru" />
   <contributor name="David Golpira"         email="golpira@alternatecomputing.com" />
   <contributor name="Jason Amy"             email="jasona@premier1.net" />
   <contributor name="Magnus Stenman"        email="magnus@orionserver.com" />
   <contributor name="Chris Miller"          email="kiwi@vardus.co.uk" />
   <contributor name="Montebove Luciano"     email="L.Montebove@finsiel.it" />
   <contributor name="Sebastiaan van Erk"    email="sebster@sebster.com" />
   <contributor name="Dennis Carroll"        email="Dennis.Carroll@DOT.STATE.MN.US" />
   <contributor name="Henry Hu"              email="henryh@keystroke.com" />
   <contributor name="Martijn van Berkum"    email="mvberkum@gx.nl" />
   <contributor name="Jeff Schnitzer"        email="jeff@infohazard.org" />
   <contributor name="Christopher R. Spence" email="vampired@mediaone.net" />
   <contributor name="Thomas Pluempe"        email="thomanski@gmx.de" />
   <contributor name="Julian Richardson"     email="JRichardson@softwright.co.uk" />
   <contributor name="Matthew Neill"         email="matthew.neill@jda.com" />

   <javadoc-location package="java/lang"          url="http://java.sun.com/j2se/1.3/docs/api/" />
   <javadoc-location package="java/util"          url="http://java.sun.com/j2se/1.3/docs/api/" />
   <javadoc-location package="java/rmi"           url="http://java.sun.com/j2se/1.3/docs/api/" />
   <javadoc-location package="javax/rmi"          url="http://java.sun.com/j2se/1.3/docs/api/" />
   <javadoc-location package="javax/ejb"          url="http://java.sun.com/products/ejb/javadoc-1.1/" />
   <javadoc-location package="javax/servlet/http" url="http://java.sun.com/products/servlet/2.3/javadoc/" />
   <javadoc-location package="javax/naming"       url="http://java.sun.com/products/jndi/1.2/javadoc/" />

   <header>
      <paragraph>This tutorial will show you how to write and run a simple
      Enterprise JavaBean using the Orion application server (<web-link
      url="http://www.orionserver.com/">www.orionserver.com</web-link>). You
      will be taught how to write and compile a simple session bean and a
      simple servlet and how to deploy and run these.</paragraph>

      <paragraph type="note">This tutorial assumes you are familiar with the
      basics of EJB and J2EE. If you are not, please read up on these subjects
      first. See the links at <internal-link lesson="main" section="refs">the
      bottom of this tutorial</internal-link>.</paragraph>
   </header>

   <lesson name="main">
      <section name="intro" title="Introduction">
         <paragraph>The goal of this tutorial is to show you a fast, easy and
         sensible way of writing and deploying a simple Enterpise JavaBean
         manually. Once you know how do this, you may find that you have less
         trouble doing more complex things.</paragraph>

         <paragraph>We will first set up a directory structure, then write
         some a few <fixed-width>.java</fixed-width> and
         <fixed-width>.xml</fixed-width> files that will form our sample
         application <italics>Hello Planet</italics>. We will then use these
         files to build a J2EE application and finally deploy this application
         in Orion. If you run into trouble, check out the links at the bottom
         of this page. If you find any inconsistencies or errors in this
         document, then please send an email to the author (see the bottom of
         this page.)</paragraph>

         <paragraph>Before you start, make sure you have downloaded and
         installed the following software:

            <list ordered="false">
               <list-item><web-link url="http://java.sun.com/j2se/">Java Development Kit (1.2 or later)</web-link></list-item>
               <list-item><web-link url="http://www.orionserver.com/">Orion (1.0 or later)</web-link></list-item>
               <list-item><web-link url="http://jakarta.apache.org/ant">Ant (1.2 or later)</web-link></list-item>
            </list>
         </paragraph>

         <paragraph type="tip" title="Installing Orion on FreeBSD">If you are
         running FreeBSD, then you can install Orion by simply installing the
         <fixed-width>www/orion</fixed-width> port. This will install
         JDK 1.2 or 1.3 too, if it not already installed:

            <list>
               <list-item>Become <fixed-width>root</fixed-width> (<fixed-width>su root</fixed-width>)</list-item>
               <list-item>Go to the directory that contains the <fixed-width>www/orion/</fixed-width> port (<fixed-width>cd /usr/ports/www/orion/</fixed-width>).</list-item>
               <list-item>Install the port (<fixed-width>make install</fixed-width>).</list-item>
            </list>
         </paragraph>

         <paragraph>This tutorial has the following sections:
            <section-listing />
         </paragraph>

         <paragraph type="fast-forward" title="Skip creating source files">Instead of following the steps involved to create the
         necessary source files, you can download all the
         <fixed-width>.java</fixed-width> and <fixed-width>.xml</fixed-width>
         files at once. This allows you to skip to <internal-link
         section="step9">step 9</internal-link>. In this case you only need to
         download and unpack either one of the following files:
            <list ordered="false">
               <list-item><src-link url="hello-planet/build/hello-planet-pkg.tar.gz">hello-planet-pkg.tar.gz</src-link></list-item>
               <list-item><src-link url="hello-planet/build/hello-planet-pkg.zip">hello-planet-pkg.zip</src-link></list-item>
            </list>
         Note that these files already contain the
         <fixed-width>build.xml</fixed-width> file, so you won't have to
         download it in <internal-link section="step9">step 9</internal-link>.
         </paragraph>

      </section>

      <section name="step1" title="Step 1: Setup directory structure">
         <paragraph>First thing we do, is setting up a directory structure that
         will contain all of the files we write and those we generate. You
         should create the <fixed-width>hello-planet</fixed-width> directory
         somewhere in your home directory, for example as
         <fixed-width>/home/john.doe/hello-planet/</fixed-width> (on
         UNIX and Linux systems) or <fixed-width>C:\hello-planet</fixed-width>
         (on Windows systems).</paragraph>

         <paragraph>Create the following directory structure:
            <paragraph>
               <fixed-width>hello-planet/
               <return />hello-planet/src/
               <return />hello-planet/src/java/
               <return />hello-planet/src/java/hello/
               <return />hello-planet/src/java/hello/ejb/
               <return />hello-planet/src/java/hello/web/
               <return />hello-planet/etc/</fixed-width>
            </paragraph>
         </paragraph>

         <paragraph>All <fixed-width>.java</fixed-width> source files will be
         placed in the <fixed-width>src/java/</fixed-width> subdirectory. If
         your project would contain JPython code as well, you would place it
         under <fixed-width>src/jpython/</fixed-width>.</paragraph>

         <paragraph>The directory
         <fixed-width>hello-planet/etc/</fixed-width> will contain all the
         necessary <fixed-width>.xml</fixed-width> files.</paragraph>

         <paragraph>The generated Java <fixed-width>.class</fixed-width> files
         will be placed in the <fixed-width>lib/java/</fixed-width>
         subdirectory. This directory will be created automatically during the
         build process, in <internal-link section="step9">step
         9</internal-link>.</paragraph>

         <paragraph>When archives are created (JAR and ZIP files), they will
         be placed in the <fixed-width>build/</fixed-width>
         subdirectory. This directory will also be created during the
         automated build process in <internal-link section="step9">step
         9</internal-link>.</paragraph>

         <paragraph>You can use
         <src-link url="makedirs.sh">makedirs.sh</src-link> (for UNIX and
         Linux systems) or
         <src-link url="makedirs.bat">makedirs.bat</src-link> (for Windows
         systems) to create the required directory structure for
         you.</paragraph>
      </section>

      <section name="step2" title="Step 2: Write the remote interfaces">

         <paragraph>First thing we should write is an interface that derives
         from <javadoc-link package="javax/ejb" class="EJBObject" /> and that
         contains the methods our bean will export.

            <paragraph type="preformatted"><bold>public interface</bold> Hello
<bold>extends</bold> <javadoc-link package="javax/ejb" class="EJBObject" /> {
   <bold>public</bold> <javadoc-link package="java/lang" class="String" /> sayHello() <bold>throws</bold> <javadoc-link package="java/rmi" class="RemoteException" />
}</paragraph>
         </paragraph>

         <paragraph type="save">Save
         <src-link url="hello-planet/src/java/hello/ejb/Hello.java">Hello.java</src-link>
         (<src-link url="hello-planet/src/java/hello/ejb/Hello.java.html">view</src-link>)
         in your
         <fixed-width>hello-planet/src/java/hello/ejb/</fixed-width>
         directory.</paragraph>
      </section>

      <section name="step3" title="Step 3: Write the bean class">

         <paragraph>Now that we have the interface that the clients will use
         (<fixed-width>Hello</fixed-width>), we will write a session bean that
         actually implements that functionality. The session bean must implement the
         interface
         <javadoc-link package="javax/ejb" class="SessionBean">javax.ejb.SessionBean</javadoc-link>.</paragraph>

         <paragraph type="preformatted"><bold>public class</bold> HelloBean
<bold>extends</bold> <javadoc-link package="java/lang" class="Object">Object</javadoc-link>
<bold>implements</bold> <javadoc-link package="javax/ejb" class="SessionBean">SessionBean</javadoc-link>
         </paragraph>

         <paragraph>Besides the method <fixed-width>sayHello()</fixed-width> in
         the <fixed-width>Hello</fixed-width> interface, we need to implement the
         following methods, because the
         <javadoc-link package="javax/ejb" class="SessionBean">SessionBean</javadoc-link>
         interface defines them:

            <list ordered="false">
               <list-item><fixed-width><bold>public void</bold> ejbActivate()</fixed-width></list-item>
               <list-item><fixed-width><bold>public void</bold> ejbPassivate()</fixed-width></list-item>
               <list-item><fixed-width><bold>public void</bold> ejbRemove()</fixed-width></list-item>
               <list-item><fixed-width><bold>public void</bold> setSessionContext(SessionContext)</fixed-width></list-item>
            </list>
         </paragraph>

         <paragraph type="save">Save
         <src-link url="hello-planet/src/java/hello/ejb/HelloBean.java">HelloBean.java</src-link>
         (<src-link url="hello-planet/src/java/hello/ejb/HelloBean.java.html">view</src-link>)
         in your
         <fixed-width>hello-planet/src/java/hello/ejb/</fixed-width> directory.</paragraph>

      </section>

      <section name="step4" title="Step 4: Write the home interface">

         <paragraph>A <italics>home interface</italics> is used to create and
         destroy instances of Enterprise JavaBeans. So we need a home
         interface for our <fixed-width>HelloBean</fixed-width> bean as
         well.</paragraph>

         <paragraph>Our home interface will be derived from
         <javadoc-link package="javax/ejb" class="EJBHome" />. We only need a
         single method at this time:

            <list ordered="false">
               <list-item><fixed-width><bold>public</bold> Hello create()</fixed-width></list-item>
            </list>
         </paragraph>

         <paragraph>This method provides the caller with an instance that
         implements the <fixed-width>Hello</fixed-width>
         interface.</paragraph>

         <paragraph type="save">Save
         <src-link url="hello-planet/src/java/hello/ejb/HelloHome.java">HelloHome.java</src-link>
         (<src-link url="hello-planet/src/java/hello/ejb/HelloHome.java.html">view</src-link>)
         in the directory
         <fixed-width>hello-planet/src/java/hello/ejb/</fixed-width>.</paragraph>

      </section>

      <section name="step5" title="Step 5: Write a servlet">

         <paragraph>In order to call the session bean and make the results
         visible, we will write a small servlet that does exactly that. We
         will derive the servlet from the base class for HTTP servlets:
         <javadoc-link package="javax/servlet/http" class="HttpServlet" />.
         When our servlet is initialized, we will let it attempt to get a
         reference to the home interface of our bean:</paragraph>

         <paragraph type="preformatted"><italics>// Get the initial JNDI context</italics>
<javadoc-link package="javax/naming" class="Context">Context</javadoc-link> context = <bold>new</bold> <javadoc-link package="javax/naming" class="InitialContext" />();

<italics>// Get a reference to the Hello interface</italics>
<javadoc-link package="java/lang" class="Object" /> boundObject = context.lookup("java:comp/env/ejb/HelloHome");
HelloHome helloHome = (HelloHome) <javadoc-link package="javax/rmi" class="PortableRemoteObject" />.narrow(boundObject, HelloHome.<bold>class</bold>);
_hello = helloHome.create();</paragraph>

         <paragraph>When our HTTP servlet is accessed, the method
         <fixed-width>doGet()</fixed-width> will be called, which will do the
         following:</paragraph>

         <paragraph type="java-code">
            <javadoc-link package="java/lang" class="String">String</javadoc-link> answer = _hello.sayHello();
            <return />
            <return />out.println("&lt;HTML&gt;&lt;BODY bgcolor=\"#FFFFFF\"&gt;");
            <return />out.println("Time stamp: " + new <javadoc-link package="java/util" class="Date">Date</javadoc-link>().toString());
            <return />out.println("&lt;BR&gt;Hello type: " + hello.getClass().getName());
            <return />out.println("&lt;BR&gt;Answer: " + answer);
            <return />out.println("&lt;/BODY&gt;");
            <return />out.println("&lt;/HTML&gt;");
         </paragraph>

         <paragraph type="save">Save
         <src-link url="hello-planet/src/java/hello/web/HelloServlet.java">HelloServlet.java</src-link>
         (<src-link url="hello-planet/src/java/hello/web/HelloServlet.java.html">view</src-link>)
         in the directory
         <fixed-width>hello-planet/src/java/hello/web/</fixed-width>.</paragraph>

      </section>

      <section name="step6" title="Step 6: Write the J2EE application definition">

         <paragraph>Next, we'll create a J2EE Application Definition file,
         <fixed-width>application.xml</fixed-width>.
         This is an XML file that defines the components of a Java 2
         Enterprise Edition application. We will include two modules at this
         time. One for the session bean, and one for the servlet.</paragraph>

         <paragraph>The module for the session bean looks as
         follows:

            <paragraph type="preformatted"><bold>&lt;module&gt;</bold>
   <bold>&lt;ejb&gt;</bold>hello-planet-ejb.jar<bold>&lt;/ejb&gt;</bold>
<bold>&lt;/module&gt;</bold></paragraph>
         </paragraph>

         <paragraph>The module for the web application is:

            <paragraph type="preformatted"><bold>&lt;module&gt;</bold>
   <bold>&lt;web&gt;</bold>
      <bold>&lt;web-uri&gt;</bold>hello-planet-web.war<bold>&lt;/web-uri&gt;</bold>
      <bold>&lt;context-root&gt;</bold>/hello-planet<bold>&lt;/context-root&gt;</bold>
   <bold>&lt;/web&gt;
&lt;/module&gt;</bold></paragraph>
         </paragraph>

         <paragraph>The complete <fixed-width>application.xml</fixed-width>
         file looks as follows:

         <paragraph type="preformatted">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN"
                             "<web-link url="http://java.sun.com/j2ee/dtds/application_1_2.dtd">http://java.sun.com/j2ee/dtds/application_1_2.dtd</web-link>"&gt;
 
<bold>&lt;application&gt;</bold>
 
   <italics>&lt;!-- The display-name element specifies the human-readable name of this
        application. It is not used to identify the application.  --&gt;</italics>
 
   <bold>&lt;display-name&gt;</bold>Hello Planet<bold>&lt;/display-name&gt;</bold>
 
 
   <italics>&lt;!-- The EJB module. All that needs to be specified is the location of the
        EJB JAR file. --&gt;</italics>
 
   <bold>&lt;module&gt;
      &lt;ejb&gt;</bold>hello-planet-ejb.jar<bold>&lt;/ejb&gt;
   &lt;/module&gt;</bold>
 
 
   <italics>&lt;!-- The web module. The context-root specifies how the web-application can
        be reached from a browser. The web-uri element specifies the location
        of the WAR file that contains the web application. --&gt;</italics>
 
   <bold>&lt;module&gt;
      &lt;web&gt;
         &lt;web-uri&gt;</bold>hello-planet-web.war<bold>&lt;/web-uri&gt;
         &lt;context-root&gt;</bold>/hello-planet<bold>&lt;/context-root&gt;
      &lt;/web&gt;
   &lt;/module&gt;
 
&lt;/application&gt;</bold></paragraph>
         </paragraph>

         <paragraph type="save">Save
         <src-link url="hello-planet/etc/application.xml">application.xml</src-link>
         in the <fixed-width>etc/</fixed-width> subdirectory.</paragraph>

      </section>

      <section name="step7" title="Step 7: Write the EJB deployment descriptor">

         <paragraph>We need to write a so-called <italics>XML deployment
         descriptor</italics> to describe the EJB part of our
         application.</paragraph>

         <paragraph>In the deployment descriptor we describe every Enterprise
         JavaBean we would like to deploy. In our case, there is only
         one:

            <paragraph><fixed-width>&lt;session&gt;
            <indent>&lt;display-name&gt;The hello.ejb.Hello session bean&lt;/display-name&gt;
               <return />&lt;ejb-name&gt;hello.ejb.Hello&lt;/ejb-name&gt;
               <return />&lt;home&gt;hello.ejb.HelloHome&lt;/home&gt;
               <return />&lt;remote&gt;hello.ejb.Hello&lt;/remote&gt;
               <return />&lt;ejb-class&gt;hello.ejb.HelloBean&lt;/ejb-class&gt;
               <return />&lt;session-type&gt;Stateless&lt;/session-type&gt;</indent>
            &lt;/session&gt;</fixed-width></paragraph>
         </paragraph>

         <paragraph type="save">Save
         <src-link url="hello-planet/etc/ejb-jar.xml">ejb-jar.xml</src-link>
         in your <fixed-width>etc/</fixed-width> subdirectory.</paragraph>

      </section>

      <section name="step8" title="Step 8: Write the Web deployment descriptor">

         <paragraph>We need a descriptor for the web-part of the application
         as well. In this file we will specify that we have a servlet
         <fixed-width>hello.web.HelloServlet</fixed-width>, as
         follows:

            <paragraph><fixed-width>&lt;servlet&gt;
               <indent>&lt;servlet-name&gt;hello.web.HelloServlet&lt;/servlet-name&gt;
               <return />&lt;description&gt;Servlet that calls the Hello bean&lt;/description&gt;
               <return />&lt;servlet-class&gt;hello.web.HelloServlet&lt;/servlet-class&gt;</indent>
            &lt;/servlet&gt;</fixed-width></paragraph>
         </paragraph>

         <paragraph type="save">Save the
         <src-link url="hello-planet/etc/web.xml">web.xml</src-link>
         file in the 
         <fixed-width>etc/</fixed-width> subdirectory.</paragraph>

      </section>

      <section name="step9" title="Step 9: Compile and create the .jar, .war and .ear files">

         <paragraph>An <fixed-width>.ear</fixed-width> file is a special form
         of a ZIP file. It contains a complete deployable J2EE application. We
         will create a file <fixed-width>hello-planet.ear</fixed-width> to
         contain the following files and directories:

            <paragraph><fixed-width>META-INF/
            <return />META-INF/application.xml
            <return />hello-planet-ejb.jar
            <return />hello-planet-web.war</fixed-width></paragraph>
         </paragraph>

         <paragraph>The <fixed-width>hello-planet-ejb.jar</fixed-width> file
         is another special ZIP file. It contains the EJB part of the
         application. We will put the following files and directories in it:

            <paragraph><fixed-width>META-INF/
            <return />META-INF/ejb-jar.xml
            <return />hello/
            <return />hello/ejb/Hello.class
            <return />hello/ejb/HelloHome.class
            <return />hello/ejb/HelloBean.class</fixed-width></paragraph>
         </paragraph>

         <paragraph>The file <fixed-width>hello-planet-web.war</fixed-width> is
         our third special ZIP file. It contains the Web part of the application.
         This is what we will put in this file: 

            <paragraph><fixed-width>WEB-INF/
            <return />WEB-INF/web.xml
            <return />WEB-INF/classes/hello/
            <return />WEB-INF/classes/hello/web/
            <return />WEB-INF/classes/hello/web/HelloServlet.class</fixed-width></paragraph>
         </paragraph>

         <paragraph>For this purpose, I have written an Ant build file that
         will compile all the <fixed-width>.java</fixed-width> files and
         create the <fixed-width>.jar</fixed-width>, <fixed-width>.war</fixed-width>
         and <fixed-width>.ear</fixed-width> files for us.</paragraph>

         <paragraph type="save">Save
         <src-link url="hello-planet/build.xml">build.xml</src-link>
         in your <fixed-width>hello-planet/</fixed-width>
         directory. You should take a look at this file and change any
         settings if necessary:

            <list ordered="false">
               <list-item>The setting <fixed-width>orion.dir</fixed-width>
               must point the directory where you installed Orion, in my case:
               <fixed-width>/usr/local/orion</fixed-width>. If you installed
               Orion in <fixed-width>D:\Orion</fixed-width>, then you would
               set this to <fixed-width>D:\Orion</fixed-width>.</list-item>

               <list-item>The setting
               <fixed-width>build.compiler</fixed-width> can be changed to
               <fixed-width>jikes</fixed-width> to improve performance,
               <EM>if</EM> you installed
               <web-link url="http://www10.software.ibm.com/developerworks/opensource/jikes/">Jikes</web-link>,
               a Java compiler by IBM.</list-item>
            </list>
         </paragraph>

         <paragraph>Now go to the <fixed-width>hello-planet</fixed-width>
         directory and execute:

            <paragraph><fixed-width>ant</fixed-width></paragraph>
         </paragraph>

         <paragraph>This typically takes less than 20 seconds, and it should
         display output similar to this:
            <paragraph type="preformatted">Searching for build.xml ...
Buildfile: /home/ernst/hello-planet/build.xml

init:

prepare:
&#160;&#160;&#160;&#160;[mkdir] Created dir: /home/ernst/hello-planet/lib
&#160;&#160;&#160;&#160;[mkdir] Created dir: /home/ernst/hello-planet/lib/ejb
&#160;&#160;&#160;&#160;[mkdir] Created dir: /home/ernst/hello-planet/lib/ejb/META-INF
&#160;&#160;&#160;&#160;[mkdir] Created dir: /home/ernst/hello-planet/lib/web
&#160;&#160;&#160;&#160;[mkdir] Created dir: /home/ernst/hello-planet/lib/web/WEB-INF
&#160;&#160;&#160;&#160;[mkdir] Created dir: /home/ernst/hello-planet/lib/web/WEB-INF/classes
&#160;&#160;&#160;&#160;[mkdir] Created dir: /home/ernst/hello-planet/lib/j2ee
&#160;&#160;&#160;&#160;[mkdir] Created dir: /home/ernst/hello-planet/lib/META-INF
&#160;&#160;&#160;&#160;[mkdir] Created dir: /home/ernst/hello-planet/build
&#160;&#160;&#160;&#160;[mkdir] Created dir: /home/ernst/hello-planet/build/hello-planet

ejb-classes:
&#160;&#160;&#160;&#160;[javac] Compiling 3 source files to /home/ernst/hello-planet/lib/ejb

ejb-meta-inf:
&#160;&#160;&#160;&#160;&#160;[copy] Copying 1 files to /home/ernst/hello-planet/lib/ejb/META-INF

ejb-jar:
&#160;&#160;&#160;&#160;&#160;&#160;[jar] Building jar: /home/ernst/hello-planet/build/hello-planet-ejb.jar

web-classes:
&#160;&#160;&#160;&#160;[javac] Compiling 1 source file to /home/ernst/hello-planet/lib/web/WEB-INF/classes

web-web-inf:
&#160;&#160;&#160;&#160;&#160;[copy] Copying 1 files to /home/ernst/hello-planet/lib/web/WEB-INF

war:
&#160;&#160;&#160;&#160;&#160;&#160;[jar] Building jar: /home/ernst/hello-planet/build/hello-planet-web.war

j2ee-meta-inf:
&#160;&#160;&#160;&#160;&#160;[copy] Copying 1 files to /home/ernst/hello-planet/lib/j2ee/META-INF

ear:
&#160;&#160;&#160;&#160;&#160;[copy] Copying 1 files to /home/ernst/hello-planet/lib/j2ee
&#160;&#160;&#160;&#160;&#160;[copy] Copying 1 files to /home/ernst/hello-planet/lib/j2ee
&#160;&#160;&#160;&#160;&#160;&#160;[jar] Building jar: /home/ernst/hello-planet/build/hello-planet.ear
BUILD SUCCESSFUL

Total time: 5 seconds</paragraph>
         </paragraph>

         <paragraph>This will (should) create the following files. Click on
         one to download the files generated on my system:

            <paragraph><fixed-width><src-link url="hello-planet/lib/ejb/hello/ejb/Hello.class">lib/ejb/hello/ejb/Hello.class</src-link>
            <return /><src-link url="hello-planet/lib/ejb/hello/ejb/HelloHome.class">lib/ejb/hello/ejb/HelloHome.class</src-link>
            <return /><src-link url="hello-planet/lib/ejb/hello/ejb/HelloBean.class">lib/ejb/hello/ejb/HelloBean.class</src-link>
            <return /><src-link url="hello-planet/lib/web/WEB-INF/classes/hello/web/HelloServlet.class">lib/web/WEB-INF/classes/hello/web/HelloServlet.class</src-link>
            <return /><src-link url="hello-planet/build/hello-planet-ejb.jar">build/hello-planet-ejb.jar</src-link>
            <return /><src-link url="hello-planet/build/hello-planet-web.war">build/hello-planet-web.war</src-link>
            <return /><src-link url="hello-planet/build/hello-planet.ear">build/hello-planet.ear</src-link></fixed-width>
            </paragraph>
         </paragraph>

         <paragraph type="troubleshoot" title="Ant fails">If running
         <fixed-width>ant</fixed-width> results in the error
            <paragraph><fixed-width>Could not create task of type: copy
            because I can't find it in the list of task class
            definitions</fixed-width></paragraph>
         then please update your version of Ant to at least 1.2. You can
         download the compiled version of Ant 1.2 from
         <web-link url="http://jakarta.apache.org/builds/jakarta-ant/release/v1.2/bin/">http://jakarta.apache.org/builds/jakarta-ant/release/v1.2/bin/</web-link>.

         <return />Otherwise, if you get a compilation error telling you that
         certain packages cannot be imported because they cannot be found,
         make sure that the <fixed-width>orion.dir</fixed-width> setting in
         your <fixed-width>build.xml</fixed-width> points to the location
         where you installed Orion.</paragraph>
      </section>

      <section name="step10" title="Step 10: Install the application">

         <paragraph>To actually install our application, we need to add a line
         to the <fixed-width>server.xml</fixed-width> file in our Orion
         configuration directory (<fixed-width>orion/config</fixed-width>). Make sure
         you add it before the closure of the main tag
         <fixed-width>&lt;/application-server&gt;</fixed-width>. This is the
         line you should add:

            <paragraph type="preformatted"><bold>&lt;application</bold> name="hello-planet" path="<italics>path to ear file</italics>" <bold>/&gt;</bold></paragraph>
         </paragraph>

         <paragraph>In my case the end of the <fixed-width>server.xml</fixed-width> file now looks like this:

            <paragraph type="preformatted">&#160;&#160;&#160;<bold>&lt;application name=</bold>"hello-planet" <bold>path=</bold>"/home/ernst/hello-planet/build/hello-planet.ear" <bold>/&gt;</bold>
<bold>&lt;/application-server&gt;</bold></paragraph>

         </paragraph>
      </section>

      <section name="step11" title="Step 11: Bind the web application">

         <paragraph>Now we need to bind the web application to the default
         site. This is done by adding the following line to the file
         <fixed-width>default-web-site.xml</fixed-width> in the Orion
         configuration directory. Again, place it before the main tag
         <fixed-width>&lt;/web-site&gt;</fixed-width>:

            <paragraph type="preformatted"><bold>&lt;web-app application=</bold>"hello-planet" <bold>name=</bold>"hello-planet-web" <bold>root=</bold>"/hello-planet" <bold>/&gt;</bold></paragraph>
         </paragraph>
      </section>

      <section name="step12" title="Step 12: Start Orion">

         <paragraph>Everything should work, so let's start Orion. Go to the
         installation directory of Orion, and execute:

            <paragraph><fixed-width>java -jar orion.jar</fixed-width></paragraph>
         </paragraph>

         <paragraph>In my case:
            <paragraph><fixed-width>$ cd /usr/local/orion
            <return />$ java -jar orion.jar</fixed-width></paragraph>
         </paragraph>

         <paragraph>Now open your favourite webbrowser, and point it to:

            <paragraph><fixed-width>http://<italics>hostname</italics>/hello-planet/</fixed-width></paragraph>
         </paragraph>

         <paragraph>In my case I am running the Orion webserver locally.
         Note that the IP address 127.0.0.1 <italics>always</italics> points
         to your own computer. So if you are running Orion on the same
         computer as the webbrowser, then you should point your browser to:

            <paragraph><fixed-width>http://127.0.0.1/hello-planet/</fixed-width></paragraph>
         </paragraph>

         <paragraph>You should now see the output of your servlet.</paragraph>

         <paragraph type="tip" title="Continue exploring Orion">After you finished this tutorial, you may want to try the <web-link url="../orion-cmp-primer/">Orion CMP Primer</web-link> for an introductory tutorial about EJB's and JSP's.</paragraph>
      </section>

      <section name="refs" title="See also">

         <paragraph>See the following documents for more information on Orion:

            <list ordered="false">
               <list-item><web-link url="http://www.orionserver.com/">Orion Website</web-link> (Orion)</list-item>
               <list-item><web-link url="http://www.orionsupport.com/">Orion Support Site</web-link> (<web-link url="mailto:joeo@cupid.suninternet.com">Joseph B.  Ottinger</web-link>)</list-item>
               <list-item><web-link url="http://www.orionserver.com/docs/application-creation-howto.html">Setting up an Application</web-link> (Orion)</list-item>
               <list-item><web-link url="http://www.orionserver.com/tutorials/">Orion Tutorial Index</web-link> (Orion)</list-item>
            </list>
         </paragraph>

         <paragraph>See the following sites for more information on J2EE, EJB and JNDI:

            <list ordered="false">
               <list-item><web-link url="http://java.sun.com/j2ee/">J2EE Homepage</web-link> (JavaSoft)</list-item>
               <list-item><web-link url="http://developer.java.sun.com/developer/technicalArticles/J2EE/Intro/">Introduction to the J2EE Architecture</web-link> (JavaSoft)</list-item>
               <list-item><web-link url="http://developer.java.sun.com/developer/onlineTraining/J2EE/Intro/index.html">J2EE tutorial</web-link> (JavaSoft)</list-item>
               <list-item><web-link url="http://developer.java.sun.com/developer/onlineTraining/EJBIntro/">EJB tutorial</web-link> (JavaSoft).</list-item>
               <list-item><web-link url="http://developer.java.sun.com/developer/products/j2ee/index.html">J2EE Technology Center</web-link> (JavaSoft)</list-item>
               <list-item><web-link url="http://www.javaworld.com/javaworld/topicalindex/jw-ti-ejb.html">Topical index: Enterprise JavaBeans</web-link> (JavaWorld)</list-item>
               <list-item><web-link url="http://java.sun.com/products/jndi/tutorial/">The JNDI Tutorial</web-link> (JavaSoft)</list-item>
               <list-item><web-link url="http://java.sun.com/products/rmi-iiop/">RMI over IIOP</web-link> (JavaSoft)</list-item>
               <list-item><web-link url="http://java.sun.com/j2ee/dtds/application_1_2.dtd">XML DTD for application.xml files</web-link> (JavaSoft)</list-item>
               <list-item><web-link url="http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd">XML DTD for ejb-jar.xml files</web-link> (JavaSoft)</list-item>
               <list-item><web-link url="http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">XML DTD for web.xml files</web-link> (JavaSoft)</list-item>
            </list>
         </paragraph>

         <paragraph>For more information about Ant, and to to download it,
         visit the following web pages:

            <list ordered="false">
               <list-item><web-link url="http://jakarta.apache.org/ant/">Ant Homepage</web-link> (Apache)</list-item>
               <list-item><web-link url="http://jakarta.apache.org/builds/jakarta-ant/release/v1.2/bin/">Download Ant</web-link> (Apache)</list-item>
            </list>
         </paragraph>

      </section>

      <section name="todo" title="To do">

         <paragraph>Things considered for a future release of this document:
            <list ordered="false">
               <list-item>Change the session bean to stateful.</list-item>
               <list-item>Add more explanatory text.</list-item>
               <list-item>Add documentation in the XML files.</list-item>
            </list>
         </paragraph>

      </section>
   </lesson>

</document>

