Compile Enterprise Beans and Create Deployable JAR files

Did you ever wonder what goes on behind the scenes when you use a visual interactive tool (such as VisualAge for Java) to create enterprise bean JAR files? Do you ever need to create EJB JAR files without such a tool?

If so, follow these steps to compile enterprise beans and create EJB JAR files that you can deploy on the WebSphere Application Server. We also provide an example batch file that automates this process for the Account and Transfer sample enterprise beans. You can modify this file for other enterprise beans you want to process, or use it as a basis for creating an automated script (such as a make file) for other operating systems.

For further details, see:

  • The source files for the sample Account and Transfer enterprise beans are in the <was_root>/hosts/default_host/WSsamples_app/servlets/
    WebSphereSamples/AccountAndTransfer directory
  • For a complete discussion on how the source files were created, see the WebSphere Application Server enterprise bean documentation.

Steps to compile enterprise beans and create EJB JAR files

  1. Compile the enterprise bean source files into class files.

    You might need to include support classes, such as exceptions, or classes in other enterprise beans. Be sure to add these class files or EJB JAR files to the compile CLASSPATH.

  2. Package the resulting class files into a JAR file. This will be the first of three JAR files in the process.

  3. Run the jetace tool. Use the first JAR file as input and add the deployment information for the enterprise bean to create the second JAR file which includes the deployment descriptor. This JAR is not a "complete" enterprise bean, but it can be deployed through the WebSphere Administrative Console.

    When you deploy the the second JAR file through the WebSphere Administrative Console, it creates the third JAR file. This final JAR file is a "complete" enterprise bean, sometimes called the deployed bean JAR file. This deployment process adds support classes, makes the enterprise beans accessible through the naming service, and creates any underlying persistent data tables.

Repeat these three steps (compile source, package into a JAR, run jetace) for each enterprise bean you are going to create and make ready for deployment. In the first step, to compile one enterprise bean that requires classes found in another enterprise bean, you can add any of the JAR files of the first enterprise bean to the compile CLASSPATH of the second enterprise bean.

About jetace

The first time you run jetace for a particular enterprise bean, you must run it in GUI (graphical user interface) mode. When in GUI mode, jetace lets you create an XML file, in addition to the output JAR file. This XML file contains all the information you enter through the GUI. It will allow you, in the future, to run jetace in line mode so you can automate this step. The next time you need to repeat this process for this enterprise bean, use the XML file as input to jetace and it will run automatically using the prior information.

Example batch file

Our example Windows NT batch file, createbeans.bat, automates this process for the sample Account and Transfer enterprise beans. The batch process starts with the Account and Transfer source files, performs all the steps above using XML files to run jetace in line mode, and creates Account and Transfer EJB JAR files. Be sure to read the comments for a detailed step-by-step explanation.

Follow our instructions to run this batch file and test your own version of the Account and Transfer enterprise beans. You can find the executable version of createbeans.bat, plus the related source and XML files, in the <was_root>/hosts/default_host/WSsamples_app/servlets/
WebSphereSamples/AccountAndTransfer directory. If you run it from this directory, the resulting servlet and client application class files will go beneath it, in the WebSphereSamples/AccountAndTransfer subdirectory.