All Examples  All EJB 1.1 Examples  All EJB 2.0 Examples

Building Enterprise JavaBean examples

WebLogic provides scripts and makefiles to build the example EJB classes, interfaces, and clients. This document describes how to build examples using both methods.

Package structure

Each EJB example includes a client application ("Client") and sometimes a servlet ("Servlet"). All EJB client examples are included in the same Java package as the EJB classes. Classes that are intended only for the client are identified by the word "Client" in the classname. Servlets are identified by "Servlet" in the classname. Classes that are intended only for the server have the word "Bean" in the classname.

Using build.xml

We provide a build script for you to build the example:

An example of a build script is build.xml.

Run the build script using the following Java ant command:
        $ ant

To build the EJB examples:

  1. Set up your environment:
    Use the setExamplesEnv script to set your WebLogic Server development environment. See Setting your up you environment for building and running the examples for more information.

  2. Move to the example subdirectory:
    Go to the subdirectory of the EJB example you want to build. For example:
    prompt> cd %WL_HOME%\samples\server\src\examples\ejb11\basic\containerManaged
  3. Run the example script:
    The EJB script takes no arguments. Simply execute the script:
    prompt> build.xml

    Each script generates the final EJB .jar file in config\examples\applications directory of the WebLogic Server distribution. The server will automatically deploy any applications contained in this directory once the server is started. If you are already running the server and build another EJB, it is automatically placed in this directory and instantly deployed. The EJB .jar file is named according to the example's directory location. For example:

    The script also builds the clients required for the example, placing the classes in the correct locations:

How the script works

The example build script performs the same steps that you would use to manually compile and package EJBs in WebLogic Server. This script makes use of the environment variables setup by the setExamplesEnv scripts. The following steps describe each command that a typical build script performs. These steps use the samples\examples\ejb11\basic\beanManaged\build.cmd script as an example.

  1. Create a staging directory:
    The script creates a directory named build in which EJB classes and deployment files are staged before they are packaged into a .jar file. XML deployment files are placed in the META-INF subdirectory of build:
    mkdir build build\META-INF
    copy *.xml build\META-INF
    

    In the next step, compiled EJB classes are also placed in the build directory, in subdirectories that match the classes' Java package structure.

  2. Compile the Java classes:
    build.xml compiles the EJB classes and interfaces into the build directory:
    javac -d build 
    Account.java AccountHome.java AccountPK.java
    ProcessingErrorException.java AccountBean.java 

  3. Package the EJB files into a .jar:
    Next, the build script uses the jar utility to create a .jar file of the subdirectories staged in build:
    cd build
    jar cv0f std_ejb11_basic_beanManaged.jar META-INF examples
    cd ..

  4. Compile the container classes using ejbc:
    Once the .jar file has been created, the build script uses ejbc to generate EJB container classes. ejbc inserts the container classes into a new .jar file, which is created in the config\examples\applications directory:
    java weblogic.ejbc -compiler javac build\std_ejb11_basic_beanManaged.jar %APPLICATIONS%\ejb11_basic_beanManaged.jar

  5. Compile the client classes:
    The script uses javac to compile the EJB example's client classes into the appropriate directories. In the beanManaged example, compiled clients are placed in the %SAMPLES_HOME%\server\stage\examples\clientclasses and directory:
    javac -d %CLIENT_CLASSES% Account.java AccountHome.java AccountPK.java ProcessingErrorException.java Client.java
    javac -d %MYSERVER%\servletclasses -classpath %MYCLASSPATH% Servlet.java
  6. Compile the servlet classes:
    The script uses javac to compile the EJB interfaces and servlet classes (if any) into the Examples Web Application classes directory. In the beanManaged example, compiled classes are placed in the %SAMPLES_HOME%\server\stage\examples\examplesWebApp\WEB-INF\classes directory:
    javac -d %EX_WEBAPP_CLASSES% Servlet.java Account.java 
    AccountHome.java AccountPK.java ProcessingErrorException.java

Getting more information

Read more about deploying WebLogic EJBs in BEA WebLogic Server Enterprise JavaBeans.

Copyright © 1997-2002 BEA Systems, Inc. All rights reserved.

Last updated 10/10/2001