<?xml version="1.0" encoding="UTF-8"?>
<section version="5.0" 
         xmlns="http://docbook.org/ns/docbook" 
         xmlns:xlink="http://www.w3.org/1999/xlink" 
         xmlns:xi="http://www.w3.org/2001/XInclude" 
         xmlns:svg="http://www.w3.org/2000/svg" 
         xmlns:mml="http://www.w3.org/1998/Math/MathML" 
         xmlns:html="http://www.w3.org/1999/xhtml" 
         xmlns:db="http://docbook.org/ns/docbook" 
         xml:lang="en" 
         xml:id="deploy.ejb">
  <info><title>Example of deploying and installing an EJB using an ejb-jar file</title></info>
  <para>
      For this example, it is assumed that a user wants to customize the deployment of the 
      AccountImpl
       bean in the JOnAS example 
      <filename>
        examples/src/eb
      </filename>
       by 
       changing the name of the database table used for the persistence of the 
      AccountImpl
      .
  </para>
  <para>
      The current directory is 
      <filename>
        $JONAS_ROOT/examples/src/eb
      </filename>
      . The user will do the following:
  </para>
  <itemizedlist>
      <listitem><para>
        Edit
        <filename>
          jonas-ejb-jar.xml
        </filename>
         and modify the value of the     
        <literal>
          &lt;jdbc-table-name&gt;
        </literal>
         element included in the     
        <literal>
          &lt;jdbc-mapping&gt;
        </literal>
         element corresponding to     
        <literal>
          AccountImpl
        </literal>
         entity.
      </para></listitem>
      <listitem><para>
        Compile
         all the 
        <literal>
          .java
        </literal>
         files present in this     directory:
        <screen>javac -d ../../classes Account.java     AccountImplBean.java AccountExplBean.java AccountHome.java     ClientAccount.java</screen>
      </para></listitem>
      <listitem><para>
        Perform deployment
        <itemizedlist>
          <listitem><para>
            Build an ejbjar file named 
            <filename>
              ejb-jar.jar
            </filename>
             with all the         corresponding classes and the two deployment descriptors:
            <screen>

mkdir -p ../../classes/META-INF
cp  ejb-jar.xml  ../../classes/META-INF/ejb-jar.xml
cp jonas-ejb-jar.xml  ../../classes/META-INF/jonas-ejb-jar.xml
cd ../../classes
jar cvf eb/ejb-jar.jar META-INF/ejb-jar.xml META-INF/jonas-ejb-jar.xml 
  eb/Account.class  eb/AccountExplBean.class  eb/AccountHome.class   eb/AccountImplBean.class
                    </screen>
          </para></listitem>
          <listitem><para>
            From the source directory, run the 
            GenIC
             generation tool         that will generate the final 
            <filename>
              ejb-jar.jar
            </filename>
             file with the         interposition classes:         
            <screen>
GenIC -d ../../classes  ejb-jar.jar            </screen>
          </para></listitem>
        </itemizedlist>
      </para></listitem>
      <listitem><para>
        Install
         the ejb-jar in the 
        <filename>
          $JONAS_ROOT/ejbjars
        </filename>
             directory:     
        <screen>
cp ../../classes/eb/ejb-jar.jar $JONAS_ROOT/ejbjars/ejb-jar.jar        </screen>
      </para></listitem>
  </itemizedlist>
  <para>
     The JOnAS application Server can now be launched using the command:
  </para>
    <screen>jonas start</screen>
    <para>
      The steps just described for building the new 
      <filename>
        ejb-jar.jar
      </filename>
       file explain the deployment process. It is generally implemented by an ANT build script.
    </para>
  <para>
      If 
      Apache ANT
       is installed on your machine, type 
      ant install
       in the 
      <filename>
        $JONAS_ROOT/examples/src
      </filename>
       directory to build and install all 
      <filename>
        ejb-jar.jar
      </filename>
       files for the examples.
       To write a 
      <filename>
        build.xml
      </filename>
       file for ANT, use the 
      <code>
        ejbjar
      </code>
       task, which is one of the optional 
      <link xlink:href="http://jakarta.apache.org/ant/manual/index.html">
        EJB task
      </link>
      s defined in ANT. The 
      <code>
        ejbjar
      </code>
       task contains a nested element called 
      <code>
        jonas
      </code>
      , which implements the deployment process described above (interposition classes generation and EJB-JAR file update). 
       Generally, the latest version of the EJB task containing an updated implementation of the 
      <code>
        jonas
      </code>
       nested element is provided with JOnAS, in 
      <filename>
        $JONAS_ROOT/lib/common/ow_jonas_ant.jar
      </filename>
      . Click here for the 
      <link xlink:href="ant-ejbjar.html#ant-ejbjar">
        documentation
      </link>
       corresponding to this new version of the jonas nested element.
       As an example, this code snippet is taken from the 
      <filename>
        $JONAS_ROOT/examples/src/alarm/build.xml
      </filename>
      : 
      <screen>

 &lt;!-- ejbjar task  --&gt;
 &lt;taskdef name="ejbjar"
    classname="org.objectweb.jonas.ant.EjbJar"
    classpath="${jonas.root}/lib/common/ow_jonas_ant.jar" /&gt;

  &lt;!-- Deploying ejbjars via ejbjar task  --&gt;
  &lt;target name="jonasejbjar"
	  description="Build and deploy the ejb-jar file"
	  depends="compile" &gt;
    &lt;ejbjar basejarname="alarm"
	    srcdir="${classes.dir}"
	    descriptordir="${src.dir}/beans/org/objectweb/alarm/beans"
            dependency="full"&gt;
      &lt;include name="**/alarm.xml"/&gt;
      &lt;support dir="${classes.dir}"&gt;
	&lt;include name="**/ViewProxy.class"/&gt;
      &lt;/support&gt;
      &lt;jonas destdir="${dist.ejbjars.dir}"
             jonasroot="${jonas.root}"
             protocols="${protocols.names}" /&gt;
    &lt;/ejbjar&gt;
  &lt;/target&gt;
      </screen>
  </para>
</section>