All Examples  All EJB Examples

Building Enterprise JavaBean examples

WebLogic provides shell 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.cmd and build.sh

Each EJB example subdirectory contains a pair of shell scripts for building the example under UNIX (build.sh) and Windows NT (build.cmd). For example:

To build EJB examples using either build.cmd or build.sh:

  1. Set your environment:
    Use the setEnv script to set your WebLogic Server development environment. If you have not yet edited setEnv to match your installation, or if you need help using setEnv, see Setting your development environment.

  2. Move to the example subdirectory:
    Go to the subdirectory of the EJB example you want to build. For example:
    $ cd c:\weblogic\examples\ejb\basic\containerManaged
  3. Run the example script:
    The EJB shell scripts take no arguments. Simply execute the script:
    $ build.cmd

    Each script generates the final EJB .jar file in /weblogic/myserver. The EJB .jar file is named according to the example's location. For example:

    The scripts also build the clients required for the example, placing the classes in the correct locations:

    Note: If you build an example EJB with the supplied build scripts and deploy it, you cannot run the build script again and redeploy the bean from the same .jar without getting an error. Instead, edit the script to build the EJB to a new .jar file, and redeploy from the new file.

How the scripts work

The example build scripts perform the same steps that you would use to manually compile and package EJBs in WebLogic Server. The following steps describe each command that a typical build script performs. These steps use the /examples/ejb/basic/beanManaged/build.cmd script as an example.

  1. Set the environment:
    The script begins by using the JDK_HOME and WL_HOME environment variables to define set the class path and output directories for building the examples:
    if not exist %JDK_HOME% set JDK_HOME=\java
    if not exist %WL_HOME% set WL_HOME=\weblogic
    set MYSERVER=%WL_HOME%\myserver
    set MYCLASSPATH=%JDK_HOME%\lib\classes.zip;%WL_HOME%\classes;%WL_HOME%\lib\weblogicaux.jar;%MYSERVER%\clientclasses
    
    JDK_HOME and WL_HOME are defined in the setEnv script, and they must exactly match your JDK and WebLogic Server installations. If they do not match your installation, edit the setEnv script using the instructions in Setting your development environment.

    Note: If JDK_HOME and WL_HOME are not defined, the build script sets these variables to default directories. However, these defaults may not correctly match your installation.

  2. 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.

  3. Compile the Java classes:
    build.cmd compiles the EJB classes and interfaces into the build directory:
    javac -d build -classpath %MYCLASSPATH%
    Account.java AccountHome.java AccountPK.java
    ProcessingErrorException.java AccountBean.java 

  4. 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_ejb_basic_beanManaged.jar META-INF examples
    cd ..

  5. 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 /weblogic/myserver directory:
    java -classpath %MYCLASSPATH%
    -Dweblogic.home=%WEBLOGICHOME% weblogic.ejbc -compiler javac
    build\std_ejb_basic_beanManaged.jar
    %MYSERVER%\ejb_basic_beanManaged.jar

  6. Compile the client classes:
    Finally, 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 /myserver/clientclasses and /myserver/servletclasses directories:
    javac -d %MYSERVER%\clientclasses -classpath %MYCLASSPATH% Account.java AccountHome.java AccountPK.java ProcessingErrorException.java Client.java
    javac -d %MYSERVER%\servletclasses -classpath %MYCLASSPATH% Servlet.java

Using GNUmakefile

WebLogic also provides a make file that you can use to generate the EJB examples. The make file contains several targets: To build an EJB example using the make file, first edit GNUmakefile to specify the correct directories for JDK_HOME and WL_HOME. You will need to edit the following lines in the make file, which define default directories:
JDK_HOME=/usr/lib/java
WL_HOME=/weblogic
After editing the file, execute the command:
$ make all

Getting more information

Read more about deploying WebLogic EJBs in Deploying EJBs with DeployerTool.

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

Last updated 02/7/2000