Sun GlassFish Enterprise Server v3 Embedded Server Guide

Using the EJB 3.1 Embeddable API with Embedded Enterprise Server

The EJB 3.1 Embeddable API is designed for unit testing of EJB modules. You must use this API with a pre-installed, nonembedded Enterprise Server instance. However, you can take advantage of the embedded Enterprise Server's ease of use by referencing the nonembedded Enterprise Server instance with the glassfish-embedded-static-shell.jar file.

Embedded Enterprise Server is not related to the EJB 3.1 Embeddable API. Neither the Embedded Server API nor the Maven plug-in apply to embeddable EJB applications.

The EJB 3.1 Embeddable API is described in Java Specification Request (JSR) 318. An ejb-embedded sample is included in the samples available at Java EE 6 Downloads or Code Samples.

ProcedureTo Use the EJB 3.1 Embeddable API with Embedded Enterprise Server

  1. To specify Enterprise Server as the Container Provider, include glassfish-embedded-static-shell.jar in the class path of your embeddable EJB application.

    See Setting the Class Path and Section 22.3.3 of the EJB 3.1 Specification, Embeddable Container Bootstrapping.

  2. Configure any required resources.

    For more information about configuring resources, see the Administration Console Online Help or Part III, Resources and Services Administration, in Sun GlassFish Enterprise Server v3 Administration Guide. The jdbc/__default Java DB database is preconfigured with all distributions of Enterprise Server.

  3. Invoke one of the createEJBContainer methods.


    Note –

    Do not deploy your embeddable EJB application or any of its dependent Java EE modules before invoking one of the createEJBContainer methods. These methods perform deployment in the background and do not load previously deployed applications or modules.


  4. To change the Instance Root Directory, set the org.glassfish.ejb.embedded.glassfish.instance.root system property value by using the createEJBContainer(Map<?, ?> properties) method.

    The default Instance Root Directory location is as-installdomains/domain1. This system property applies only to embeddable EJB applications used with nonembedded Enterprise Server.

  5. Close the EJB container properly to release all acquired resources and threads.