EJB (Enterprise Java Bean) - Hello World 2001

(Windows 98; J2EE; JBoss 2.4.3; Ant 1.4)


 

  • Environment:

This complete walk-through guide to set and run EJB assumes the following:

  • JAVA_HOME = D:\Program Files\jdk1.3.1_01
  • J2EE_HOME = D:\Program Files\j2sdkee1.3
  • ANT_HOME = D:\Program Files\jakarta-ant-1.4
  • JBOSS_DIST = D:\Program Files\JBoss-2.4.3
  • DEMO_HOME = E:\
Download the Demo sample, extract it and test it.

 

  • Edit "c:\autoexec.bat" with the following:

rem (JAVA)
rem
set JAVA_HOME=d:\progra~1\jdk1.3.1_01
set CLASSPATH=.;d:\progra~1\j2sdkee1.3\lib\j2ee.jar
rem
rem (/JAVA)

rem (ANT)
rem
set ANT_HOME=D:\Progra~1\jakarta-ant-1.4
set CLASSPATH=%CLASSPATH%;%ANT_HOME%\lib\ant.jar
set PATH=%PATH%;%ANT_HOME%\bin
rem
rem (/ANT)

rem (JBOSS)
rem
set JBOSS_DIST=d:\progra~1\JBoss-2.4.3
set JBOSS_CLASSPATH=%JBOSS_DIST%\bin\run.jar
set JBOSS_CLASSPATH=%JBOSS_CLASSPATH%;%JBOSS_DIST%\lib\crimson.jar
rem
rem (/JBOSS)

rem (JBOSS_CLIENT)
rem
set CLASSPATH=%CLASSPATH%;%JBOSS_DIST%\admin\client\lib\jnp-client.jar
rem
rem (/JBOSS_CLIENT)

 

  • Restart the computer:

Restart the computer for the new environment variables to be built-in to memory.

 

  • Download and install jakarta-ant-1.4 "d:\program files\jakarta-ant-1.4" then test running "ant.bat" with "build.xml":

<!-- Simple Ant build script to test an Ant installation -->
<project name="TestInstall" default="run" basedir=".">

  <target name="init">
    <available file="ASimpleHelloObject.java" property="ASimpleHelloObject"/>
  </target>

  <target name="ASimpleHelloObject" unless="ASimpleHelloObject" depends="init">
    <echo file="ASimpleHelloObject.java">
public class ASimpleHelloObject
{
    public static void main(String[] args)
    {
        System.out.println("ASimpleHelloObject.main was called");
    }
}
    </echo>
    <echo message="Wrote ASimpleHelloObject.java" />
  </target>

  <target name="compile" depends="ASimpleHelloObject">
    <javac destdir="." srcdir="." debug="on" classpath=".">
        <include name="ASimpleHelloObject.java"/>
    </javac>
  </target>

  <target name="run" depends="compile">
    <java classname="ASimpleHelloObject" classpath="." />
    <echo message="Ant appears to be successfully installed" />
  </target>

</project>

 

  • Download and install JBoss-2.4.3 (d:\program files\jboss-2.4.3) then run "run.bat" under "d:\program files\jboss-2.4.3\bin":

To shut down the JBoss Application Server, press Ctrl-C.

 

  • Prepare demo sample to test with:

Create the directory to place "E:\org\jboss\docs\demo" your source code with.

 

  • Create Bean "DemoBean.java" under "E:\org\jboss\docs\demo":

package org.jboss.docs.demo;

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

public class DemoBean
  implements javax.ejb.SessionBean
{
  private java.lang.String string;

  public DemoBean
  (
  )
  {
    super();

    this.setString("");

    return;
  }

  public void ejbCreate
  (
  )
  {
    java.lang.System.out.println("ejbCreate called");

    return;
  }

  public void ejbPostCreate
  (
  )
  {
    java.lang.System.out.println("ejbPostCreate called");

    return;
  }

  public void ejbRemove
  (
  )
  {
    java.lang.System.out.println("ejbRemove called");

    return;
  }

  public void ejbActivate
  (
  )
  {
    java.lang.System.out.println("ejbActivate called");

    return;
  }

  public void ejbPassivate
  (
  )
  {
    java.lang.System.out.println("ejbPassivate called");

    return;
  }

  public void setSessionContext
  (
    javax.ejb.SessionContext sessionContextValue
  )
  {
    java.lang.System.out.println("setSessionContext called");

    return;
  }

/*
// Business Logic
*/
  public void setString
  (
    java.lang.String stringValue
  )
  {
    this.string = new java.lang.String(stringValue);

    return;
  }

  public java.lang.String getString
  (
  )
  {
    return this.string;
  }
}

 

  • Create Home Interface "DemoHome.java" under "E:\org\jboss\docs\demo":

package org.jboss.docs.demo;

import java.lang.*;
import java.io.*;   // Serializable
import java.rmi.*;  // RemoteException
import javax.ejb.*; // CreateException, EJBHome

import org.jboss.docs.demo.Demo;

public interface DemoHome
  extends javax.ejb.EJBHome
{
  public org.jboss.docs.demo.Demo create
  (
  )
  throws javax.ejb.CreateException,
         java.rmi.RemoteException;
}

 

  • Create Remote Interface "Demo.java" under "E:\org\jboss\docs\demo":

package org.jboss.docs.demo;

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

public interface Demo
  extends javax.ejb.EJBObject,
          java.rmi.Remote
{
  public void setString
  (
    java.lang.String stringValue
  )
  throws java.rmi.RemoteException;

  public java.lang.String getString
  (
  )
  throws java.rmi.RemoteException;
}

 

  • Create Client "DemoClient.java" under "E:\org\jboss\docs\demo":

package org.jboss.docs.demo;

import java.lang.*;
import javax.naming.*;        // InitialContext
import javax.rmi.*;           // PortableRemoteObject;
import org.jboss.docs.demo.*; // Demo, DemoHome

public class DemoClient
{
  public static void main
  (
    java.lang.String argv[]
  )
  {
    try
    {
      // Get a naming context
      javax.naming.InitialContext jndiContext =
        new javax.naming.InitialContext();
      java.lang.System.out.println("Got context");
   
      // Get a reference to the Demo Bean
      java.lang.Object reference  = jndiContext.lookup("demo/Demo");
      java.lang.System.out.println("Got reference");
         
      // Get a reference from this to the Bean's Home interface
      org.jboss.docs.demo.DemoHome home =
        (org.jboss.docs.demo.DemoHome)
        javax.rmi.PortableRemoteObject.narrow
        (
          reference,
          org.jboss.docs.demo.DemoHome.class
        );
         
      // Create an Demo object from the Home interface
      org.jboss.docs.demo.Demo demo = home.create();
         
      // call the setString() method
      demo.setString("Hello World");
      java.lang.System.out.println(demo.getString());
    }
    catch
    (
      java.lang.Exception exceptionValue
    )
    {
      java.lang.System.out.println(exceptionValue.toString());

      return;
    }

    return;
  }
}

 

  • Prepare for Deployment.

 

  • Create "build.xml" under "E:\":

<?xml version="1.0" encoding="UTF-8" ?>
<!-- An Ant build file for the Demo EJB example
-->

<project name="Demo Build Script" default="ejb-jar" basedir=".">

<!-- Modified -->
    <property name="src.dir" value="${basedir}"/>
<!-- /Modified -->

    <property name="build.demo.dir" value="${basedir}/build-examples/demo"/>
    <property name="build.classes.dir" value="${basedir}/build-examples/demo/classes"/>

    <target name="compile">
      <mkdir dir="${build.classes.dir}"/>
      <javac srcdir="${src.dir}"
           destdir="${build.classes.dir}"
           debug="on"
           deprecation="on"
           optimize="off"
      >
       <classpath path="${classpath}" />
       <include name="org/jboss/docs/demo/Demo.java" />
       <include name="org/jboss/docs/demo/DemoBean.java" />
       <include name="org/jboss/docs/demo/DemoHome.java" />
       <include name="org/jboss/docs/demo/DemoClient.java" />
      </javac>
    </target>

<!--
    <target name="compile-servlet">
      <mkdir dir="${build.classes.dir}"/>
      <javac srcdir="${src.dir}"
           destdir="${build.classes.dir}"
           debug="on"
           deprecation="on"
           optimize="off"
      >
       <classpath path="${classpath}" />
       <include name="org/jboss/docs/demo/DemoServlet.java" />
      </javac>
    </target>
-->

    <!-- Tutorial ejb jar -->
    <target name="ejb-jar" depends="compile">
        <delete dir="${build.demo.dir}/META-INF"/>
        <mkdir dir="${build.demo.dir}/META-INF"/>
        <copy file="${src.dir}/org/jboss/docs/demo/ejb-jar.xml" todir="${build.demo.dir}/META-INF" />
        <copy file="${src.dir}/org/jboss/docs/demo/jboss.xml" todir="${build.demo.dir}/META-INF" />
        <jar jarfile="${build.demo.dir}/demo.jar">
            <fileset dir="${build.classes.dir}">
                <include name="org/jboss/docs/demo/Demo.class" />
                <include name="org/jboss/docs/demo/DemoHome.class" />
                <include name="org/jboss/docs/demo/DemoBean.class" />
            </fileset>
            <fileset dir="${build.demo.dir}">
                <include name="META-INF/ejb-jar.xml" />
                <include name="META-INF/jboss.xml" />
            </fileset>
        </jar>
    </target>

    <!-- Tutorial web app war -->
<!--
    <target name="war" depends="compile-servlet">
        <delete dir="${build.demo.dir}/WEB-INF"/>
        <mkdir dir="${build.demo.dir}/WEB-INF/classes/org/jboss/docs/demo"/>
        <copy file="${src.dir}/org/jboss/docs/demo/web.xml" todir="${build.demo.dir}/WEB-INF" />
        <copy file="${src.dir}/org/jboss/docs/demo/jboss-web.xml" todir="${build.demo.dir}/WEB-INF" />
        <copy file="${src.dir}/org/jboss/docs/demo/home.html" todir="${build.demo.dir}" />
        <copy file="${build.classes.dir}/org/jboss/docs/demo/DemoServlet.class" todir="${build.demo.dir}/WEB-INF/classes/org/jboss/docs/demo" />
        <jar jarfile="${build.demo.dir}/demo.war">
            <fileset dir="${build.demo.dir}">
                <include name="WEB-INF/**"/>
                <include name="home.html"/>
            </fileset>
        </jar>
    </target>
-->
    <!-- Create the tutorial ear that uses the properties based security info -->
<!--
    <target name="ear" depends="ejb-jar,war">
        <copy file="${src.dir}/org/jboss/docs/demo/application.xml" todir="${build.demo.dir}/META-INF" />
        <jar jarfile="${build.demo.dir}/demo.ear">
            <fileset dir="${build.demo.dir}">
                <include name="META-INF/application.xml" />
                <include name="demo.jar" />
                <include name="demo.war" />
            </fileset>
        </jar>
    </target>
-->

    <target name="deploy-ejb-jar" depends="ejb-jar">
        <copy file="${build.demo.dir}/demo.jar" todir="${jboss.dist}/deploy" />
    </target>

<!--
    <target name="deploy-ear" depends="ear">
        <copy file="${build.demo.dir}/demo.ear" todir="${jboss.dist}/deploy" />
    </target>
-->

    <target name="demo-client" depends="compile">
        <java classname="org.jboss.docs.demo.DemoClient" fork="yes">
            <classpath>
               <pathelement path="${classpath}"/>
               <pathelement location="${build.classes.dir}"/>
               <pathelement location="${src.resources}"/>
            </classpath>
        </java>
    </target>
</project>

 

  • Create "ejb-jar.xml" under "E:\org\jboss\docs\demo":

<?xml version="1.0" encoding="UTF-8"?>

<ejb-jar>
     <description>JBoss Demo Application</description>
     <display-name>Demo EJB</display-name>
     <enterprise-beans>
       <session>
         <ejb-name>Demo</ejb-name>
         <home>org.jboss.docs.demo.DemoHome</home>
         <remote>org.jboss.docs.demo.Demo</remote>
         <ejb-class>org.jboss.docs.demo.DemoBean</ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Bean</transaction-type>
       </session>
     </enterprise-beans>
</ejb-jar>

 

  • Create "jboss.xml" under "E:\org\jboss\docs\demo":

<?xml version="1.0" encoding="UTF-8"?>
<jboss>
  <enterprise-beans>
    <session>
      <ejb-name>Demo</ejb-name>
      <jndi-name>demo/Demo</jndi-name>
    </session>
  </enterprise-beans>
</jboss>

 

  • Run "ant.bat" under "E:\org\jboss\docs\demo":

This is to invoke the new "build.xml" to build the "demo.jar" file under "e:\build-examples\demo".

 

  • Deploy the Package.

 

  • Create "build.xml" under "E:\build":

<?xml version="1.0" encoding="UTF-8" ?>
<!-- 
        Ant build file for the documentation tutorial code
        Writer of a chapter with an example have to include a foroward
        to their build file.  This latest build file suppose arguments 
        sets here :
                src.dir : Directory where the source are : manual\src\examples
                build.dir : Base directory where to store generated files (class/ejb/war/...)
                classpath : Classpath used to make any compilation (set up here by verifing 
                        which version of JBoss is used.
        
  -->

<project name="CMP" default="main" basedir="../">

    <property environment="env" />
    <!-- Override with your JBoss server dist location if the JBOSS_DIST env var is not set -->
    <property name="jboss.dist" value="${env.JBOSS_DIST}"/>

    <property name="src.dir" value="${basedir}"/>
    <property name="src.resources" value="${basedir}/resources"/>
    <property name="build.dir" value="${basedir}/build-examples"/>
    <property name="dist.dir" value="${basedir}/../../dist-examples"/>

    <target name="validate-servlet">
        <!-- Override with your web server servlet jar location. 
             The default assumes that JBOSS_DIST points to a 
             JBoss/Tomcat bundle distribution
         -->
        <available property="servlet.jar" value="${env.JBOSS_DIST}/../tomcat/lib/servlet.jar" file="${env.JBOSS_DIST}/../tomcat/lib/servlet.jar"/>
        <available property="servlet.jar" value="${env.JBOSS_DIST}/../jetty/lib/javax.servlet.jar" file="${env.JBOSS_DIST}/../jetty/lib/javax.servlet.jar"/>
        <available property="servlet.jar" value="${env.JBOSS_DIST}/../catalina/common/lib/servlet.jar" file="${env.JBOSS_DIST}/../catalina/common/lib/servlet.jar"/>
        <available property="servlet.jar" value="${env.JBOSS_DIST}/../catalina/common/lib/servlet.jar" file="${env.TOMCAT_HOME}/lib/servlet.jar"/>
        <property name="servlet.jar" value="COULD_NOT_FIND_SERVLET_JAR"/>

        <path id="base.path_22">
            <pathelement location="${jboss.dist}/client/ejb.jar"/>
            <pathelement location="${jboss.dist}/client/jaas.jar"/>
            <pathelement location="${jboss.dist}/client/jbosssx-client.jar"/>
            <pathelement location="${jboss.dist}/client/jboss-client.jar"/>
            <pathelement location="${jboss.dist}/client/jnp-client.jar"/>
            <pathelement location="${servlet.jar}"/>
        </path>
        <path id="base.path_24">
            <pathelement location="${jboss.dist}/client/jboss-j2ee.jar"/>
            <pathelement location="${jboss.dist}/client/jaas.jar"/>
            <pathelement location="${jboss.dist}/client/jbosssx-client.jar"/>
            <pathelement location="${jboss.dist}/client/jboss-client.jar"/>
            <pathelement location="${jboss.dist}/client/jnp-client.jar"/>
            <pathelement location="${servlet.jar}"/>
        </path>
    </target>

    <target name="validate-jboss" depends="validate-servlet">
        <available property="classpath_id" value="base.path_22" file="${jboss.dist}/client/ejb.jar" />
        <available property="classpath_id" value="base.path_24" file="${jboss.dist}/client/jboss-j2ee.jar" />

    </target>
    
    <target name="fail_if_not_valid" unless="classpath_id">
        <fail message="jboss.dist=${jboss.dist} is not a valid JBOSS_DIST directory. If using a bundled JBoss version set JBOSS_DIST to the jboss/ subdir."/>
    </target>
    
    <target name="init" depends="validate-jboss,fail_if_not_valid">
        <property name="classpath" refid="${classpath_id}" />
        <echo message="Using JBoss directory=${jboss.dist}" />
        <echo message="Using base classpath=${classpath}" />
        <echo message="Using Source directory=${src.dir}" />
        <echo message="Using Build directory=${build.dir}" />
    </target>
    
    <!-- Clean build and dist -->
    <target name="clean" depends="init">
        <delete dir="${build.dir}"/>
        <delete dir="${dist.dir}"/>
    </target>

        <!-- No default Target -->
    <target name="main" depends="init">
                <echo message="Specify which target you want to run. Example: build cmp-cd-list" />
    </target>
    
        <!-- Target to create files to store on the Web site -->
        
    <target name="dist" depends="clean">
        <mkdir dir="${dist.dir}"/>
        <!-- Bundle all the sources and build script in one file -->
        <zip zipfile="${dist.dir}/documentation-example.zip" basedir="${src.dir}/../"
          includes="examples/**" />
      <tar tarfile="${dist.dir}/documentation-example.tar" basedir="${src.dir}/../"
          includes="examples/**" />
      <gzip src="${dist.dir}/documentation-example.tar" zipfile="${dist.dir}/documentation-example.tar.gz" />
                <!-- Add Chapter specific files here 
                <antcall target="cmp-cd-dist" />
                -->
    </target>

    <!-- *************************************************************************** -->
    <!-- Chapter 1 - First Steps -->
    <target name="intro-interest-compile" depends="init">
        <ant antfile="org/jboss/docs/interest/build.xml" target="compile" />
    </target>

    <target name="intro-interest-jar" depends="init">
        <ant antfile="org/jboss/docs/interest/build.xml" target="ejb-jar" />
    </target>

    <target name="intro-interest-ear" depends="init">
        <ant antfile="org/jboss/docs/interest/build.xml" target="ear" />
    </target>

    <target name="intro-interest-deploy" depends="init">
        <ant antfile="org/jboss/docs/interest/build.xml" target="deploy-ejb-jar" />
    </target>

    <target name="intro-interest-client" depends="init">
        <ant antfile="org/jboss/docs/interest/build.xml" target="interest-client" />
    </target>


    <!-- *************************************************************************** -->
    <!-- Chapter 4 - CMP -->
        
    <target name="cmp-cd-compile" depends="init">
        <ant antfile="org/jboss/docs/cmp/cd/build/build-cmp-cd-compile.xml" target="main" />
    </target>
    
    <target name="cmp-cd-dist" depends="cmp-cd-compile">
        <!-- Nothing special here -->
    </target>
    
    <target name="cmp-cd-list" depends="init">
        <ant antfile="org/jboss/docs/cmp/cd/build/build-client.xml" target="main">
            <property name="client" value="List"/>
        </ant>
    </target>
    
    <target name="cmp-cd-upload" depends="init">
        <ant antfile="org/jboss/docs/cmp/cd/build/build-client.xml" target="main">
            <property name="client" value="Upload"/>
        </ant>
    </target>

    <target name="cmp-cd-remove" depends="init">
        <ant antfile="org/jboss/docs/cmp/cd/build/build-client.xml" target="main">
            <property name="client" value="Remove"/>
        </ant>
    </target>
    
    <!-- *************************************************************************** -->
        <!-- Chapter 5 - JAWS -->
        
    <target name="cmp-jaws-compile" depends="init">
        <ant antfile="org/jboss/docs/cmp/jaws/build/build-cmp-jaws-compile.xml" target="main" />
    </target>


        <!-- *************************************************************************** -->
        <!-- Chapter 7 - JMS -->
        
    <target name="jms-compile" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="compile" />
    </target>

    <target name="jms-build" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="build" />
    </target>

     <target name="jms-hello-publisher" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-publisher" />
    </target>

   <target name="jms-hello-subscriber" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-subscriber" />
    </target>

    <target name="jms-hello-publisher25" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-publisher25" />
    </target>

   <target name="jms-hello-subscriber25" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-subscriber25" />
    </target>

     <target name="jms-hello-sender" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-sender" />
    </target>

   <target name="jms-hello-receiver" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-receiver" />
    </target>

    <target name="jms-hello-sender25" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-sender25" />
    </target>

   <target name="jms-hello-receiver25" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-receiver25" />
    </target>

   <target name="jms-manual-jndi" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-manual-jndi" />
    </target>

      <target name="jms-create-dest" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-create-dest" />
    </target>

    <target name="jms-destroy-dest" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-destroy-dest" />
    </target>


      <target name="jms-create-dest25" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-create-dest25" />
    </target>

    <target name="jms-destroy-dest25" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-destroy-dest25" />
    </target>

     <target name="jms-hello-topic" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-topic" />
    </target>

     <target name="jms-hello-topic-durable" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-topic-durable" />
    </target>

     <target name="jms-hello-topic-fullconf" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-topic-fullconf" />
     </target>
     <target name="jms-hello-queue" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-queue" />
    </target>

    <target name="jms-hello-queue-bmt" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-queue-bmt" />
    </target>

   <target name="jms-hello-listener" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-hello-listener" />
    </target>

   <target name="jms-topic-hello24" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-topic-hello24" />
    </target>
   <target name="jms-topic-hello22" depends="init">
        <ant antfile="org/jboss/docs/jms/build.xml" target="jms-topic-hello22" />
    </target>

 <!-- *************************************************************************** -->
        <!-- Chapter  JavaMail -->
        
    <target name="howto-javamail-compile" depends="init">
        <ant antfile="org/jboss/docs/javamail/build.xml" target="compile" />
    </target>

    <target name="howto-javamail-jar" depends="init">
        <ant antfile="org/jboss/docs/javamail/build.xml" target="ejb-jar" />
    </target>

    <target name="howto-javamail-deploy" depends="init">
        <ant antfile="org/jboss/docs/javamail/build.xml" target="deploy-ejb-jar" />
    </target>

    <target name="howto-javamail-deploy-ear" depends="init">
        <ant antfile="org/jboss/docs/javamail/build.xml" target="deploy-ear" />
    </target>

    <target name="howto-javamail-client" depends="init">
        <ant antfile="org/jboss/docs/javamail/build.xml" target="javamail-client" />
    </target>

        <!-- Chapter  Applet Client -->

    <target name="howto-appletclient-compile" depends="init">
        <ant antfile="org/jboss/docs/appletclient/build.xml" target="compile" />
    </target>

    <target name="howto-appletclient-jar" depends="init">
        <ant antfile="org/jboss/docs/appletclient/build.xml" target="ejb-jar" />
    </target>

    <target name="howto-appletclient-deploy" depends="init">
        <ant antfile="org/jboss/docs/appletclient/build.xml" target="deploy-ejb-jar" />
    </target>

    <target name="howto-appletclient-client" depends="init">
        <ant antfile="org/jboss/docs/appletclient/build.xml" target="appletclient-client" />
    </target>

        <!-- Add a new target here -->

<!-- Demo -->
    <target name="sample-demo-compile" depends="init">
        <ant antfile="build.xml" target="compile" />
    </target>

    <target name="sample-demo-jar" depends="init">
        <ant antfile="build.xml" target="ejb-jar" />
    </target>

    <target name="sample-demo-deploy" depends="init">
        <ant antfile="build.xml" target="deploy-ejb-jar" />
    </target>

    <target name="sample-demo-client" depends="init">
        <ant antfile="build.xml" target="demo-client" />
    </target>
<!-- /Demo -->

</project>

 

  • Run "ant.bat sample-demo-compile sample-demo-jar sample-demo-deploy sample-demo-client" under "e:\build\".

This will compile the code, archive them into a jar package archive, deploy it into the application server container and run the client to call the deployed package.

 

  • Testing with the Client.

 

  • Create "jndi.properties" under "E:\build-examples\demo\classes":

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099

 

  • Create "server.policy" under "E:\build-examples\demo\classes":

grant {
        // Allow everything for now
        permission java.security.AllPermission;
};

 

  • Under "e:\build-examples\demo\classes", type:

java -Djava.security.manager -Djava.security.policy="server.policy" org.jboss.docs.demo.DemoClient




 

  • Important Notes:

Java Packages

  • Make sure that when executing by its package reference, the directory should also be relative to the package.
    e.g. java org.jboss.docs.demo.DemoClient
    Make sure that there is a DemoClient.class in ./org/jboss/docs/demo
    




 

  • Error Symptoms:

  • Possible Cause: "j2ee.jar" class is not included in the classpath when compiling the source code.
    package javax.ejb does not exist
    

  • Possible Cause: "ant.jar" class is not included in the classpath when trying to run "ant.bat".
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/
    Main
    

  • Possible Cause: "demo.jar" not deployed to the "D:\Program Files\JBoss-2.4.3\deploy" directory.
    javax.naming.NameNotFoundException: Demo not bound
    

  • Possible Cause: jnp-client.class not included in classpath when compiling/executing.
    javax.naming.NoInitialContextException: Cannot instantiate class:
    org.jnp.interfaces.NamingContextFactory [Root exception is
    java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
    

  • Possible Cause: java.security.manager not specified.
    javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException:
    org.jboss.ejb.plugins.jrmp13.interfaces.HomeProxy (no security manager:
    RMI class loader disabled)]
    

  • Possible Cause: java.security.policy not specified.
    java.security.AccessControlException: access denied (java.net.SocketPermission
    127.0.0.1:1099 connect,resolve)
    

  • Possible Cause: JBoss Application Server may not be running.
    javax.naming.ServiceUnavailableException: Connection refused:
    connect [Root exception is java.net.ConnectException: Connection refused: connect]
    


 

Primac Systems Limited

Copyright 2001

 

Hosted by www.Geocities.ws

1