link to table of contentsgo to previous topiclink to glossaryindex of terms


Generate and Deploy the Session Bean

Now that you have finished developing your bean, you can test it by deploying it to an application server. JBoss, the EJB server that ships with AppComposer, allows you to test your EJBs in a deployment environment.

To deploy the EJB that you built to a different application server (usually the one that runs your web applications) you have to save the EJB capsule as a jar file. When you save an EJB capsule as a jar file, AppComposer compiles and generates the bean implementation, remote interface, and home interface. It places these resources in a package called acejb. AppComposer also generates ejb-jar.xml, the deployment descriptor for the bean, and puts it in the jar file's META-INF directory. Before you generate the jar file, you need to define a data source that goes into the deployment descriptor file. Instead of having to edit the ejb-jar.xml file by hand, AppComposer allows you to add an EJB resource while building the capsule. It is automatically included when AppComposer generates the bean's deployment descriptor.

Using Data Sources in EJBs

When building this capsule, the database interactions you configured in the SQL select and update actors were made directly through JDBC. This is fine for building behaviors, but when running a session bean from an EJB server, you usually must set up a data source that corresponds to the correct database connection. This allows the application server to manage access to the particular database across whatever applications it is running. The EJB using the data source needs to designate it using its deployment descriptor.

Session EJB capsules have a section of the details pane called EJB Resources. Use this pane to set up a data source with the following attributes. AppComposer adds this to the deployment descriptor when you save the EJB capsule as a jar.

  1. Select SimpleBankEJB in the outline.
  2. In the details pane, click the icon next to EJBResources
  3. Set ResourceAuth to Container. This directs the container to control this resource.
  4. Set ResourceName to jdbc/DefaultDS. This is the name of the JBoss container's data source.
  5. Set ResourceType to javax.sql.DataSource. In this case the type of the resource is a data source. For this example, the JBoss container includes a data source resource that corresponds to the correct runtime resource.
  6. Click OK.

Now you are ready to generate the bean from the capsule.

To create and deploy a session EJB from the capsule:

  1. Save your capsule (as SimpleBankEJB.zac, if this is the first time you've saved it).
  2. From the File menu, choose Save as Jar.
  3. Use the default name, SimpleBankEJB.jar.
  4. Click Yes to import the EJB into AppComposer.
  5. Click Yes to deploy the EJB to JBoss.
  6. Open the Insert -> EJBGen -> acejb menu item to check that your EJB imported successfully.
  7. If you receive compile errors, revisit the section of the tutorial that builds the behavior or actor that the compile error refers to.

Deploying to an Application Server

Before you try to use the session bean, change the URL of the data source that the bean uses from the JDBC URL used for development to the URL of the datasource defined in JBoss.

AppComposer uses a different URL for the EJB during construction and editing of the session bean capsule. The ejbdata.url allows the container to find information it needs to connect the EJB capsule and its database. If you use a text editor to open the AppComposer/ file, you see an entry that looks like:


Application server environments generally use configured Data Sources rather than getting database connections directly through JDBC. To use the session bean, change the URL of the ejbdata connection to that of the name of the data source you defined for JBoss. Only EJB capsules need this change between edit time and runtime, so they can fully utilize the enterprise resources of the EJB server. Data sources are only available when accessed from within an application server, so when building the query, you used the JDBC URL directly.

To set the URL for the Data Source:

  1. Use a text editor to open the file. Find it in AppComposer's main directory.
  2. Remove the # character from the line: #ejbdata.url=java:/DefaultDS.
  3. Add a # character at the beginning of the line that reads: ejbdata.url=jdbc:pointbase://
  4. The group of lines should now look like this:
  5. Save and close the file.
  6. Restart AppComposer. This activates the new version of the URL.

Use the EJB!

You now have a runnable EJB that you can use in AppComposer capsules or other development environments. It is deployed and ready to test. AppComposer includes a servlet capsule named SimpleBankServlet.zac that you can use to test your session bean. This capsule acts as the client to the session bean.

  1. Open the SimpleBankServlet.zac servlet.
  2. Make sure the debug server is enabled.
  3. Run the servlet

Basically, each time the servlet runs, it creates an instance of a SimpleBankEJB with the account number "111111". The servlet displays the account holder's name and current balance, and withdraws $500.00 from the account. If you run the servlet a second time, you see that the balance is lower because of the original withdrawal. The withdraw method commits to the database because the its transaction level is set to "Required". If running in an application server other than JBoss, you need to include the file in the base directory of the application server installation.

Congratulations! You have successfully built a complex session bean capsule, deployed it, and tried using it as an actor in another capsule.

For more information on building, designing and using session EJBs, and for details on types of session beans not discussed here, see:


link to table of contentsgo to previous topiclink to glossaryindex of terms © 2003 DigiSlice Corporation