The EJB 3.1 Embeddable API is designed for unit testing of EJB modules. You must use this API with a pre-installed GlassFish Server instance. However, you can take advantage of Embedded GlassFish Server's ease of use by referencing the GlassFish Server instance with the glassfish-embedded-static-shell.jar file.
The EJB 3.1 Embeddable API supports all EJB 3.1 Lite features with addition of the EJB timer service and testing of EJB modules packaged in a WAR file.
For EJB modules in a WAR file (or an exploded directory), if a web application has one EJB module, and there are no other EJB modules in the classpath, those entries (libraries) are ignored. If there are other EJB modules, a temporary EAR file is created. For EJB modules in a WAR file to be tested, the client code must use EJB modules with interfaces or without annotations. Those EJB modules are not part of the classpath and can't be loaded by the client class loader.
The following topics are addressed here:
Reference the glassfish-embedded-static-shell.jar file from the as-install/glassfish/lib/embedded directory of a GlassFish Server installation. Do not move this file or it will not work.
See Section 22.3.3 of the EJB 3.1 Specification, Embeddable Container Bootstrapping.
For more information about configuring resources, see the Administration Console Online Help or Part II, Resources and Services Administration, in Oracle GlassFish Server 3.1 Administration Guide. The jdbc/__default Java DB database is preconfigured with all distributions of GlassFish Server. However, you must start the database manually.
If your embeddable EJB application uses Java Persistence, you do not need to specify a JDBC resource. See Default Java Persistence Data Source for Embedded GlassFish Server.
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.
The default Instance Root Directory location is as-install/domains/domain1. This system property applies only to embeddable EJB applications used with Embedded GlassFish Server.
Properties that can be passed to the EJBContainer#createEJBContainer(Properties) method are summarized in the following table. All properties are in the org.glassfish.ejb.embedded.glassfish package. For example, the full name of the installation.root property is org.glassfish.ejb.embedded.glassfish.installation.root.
Table 5 EJB 3.1 Embeddable API Properties