JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle GlassFish Server 3.1 Embedded Server Guide
search filter icon
search icon

Document Information

Preface

Oracle GlassFish Server 3.1 Embedded Server Guide

Introduction to Embedded GlassFish Server

Embedded GlassFish Server File System

Installation Root Directory

Instance Root Directory

The domain.xml File

Including the GlassFish Server Embedded Server API in Applications

Setting the Class Path

Creating, Starting, and Stopping Embedded GlassFish Server

Creating and Configuring an Embedded GlassFish Server

Running an Embedded GlassFish Server

Setting the Port of an Embedded GlassFish Server From an Application

Starting an Embedded GlassFish Server From an Application

Stopping an Embedded GlassFish Server From an Application

Deploying and Undeploying an Application in an Embedded GlassFish Server

To Deploy an Application From an Archive File or a Directory

Undeploying an Application

Creating a Scattered Archive

Creating a Scattered Enterprise Archive

Running asadmin Commands Using the GlassFish Server Embedded Server API

Sample Applications

Using the EJB 3.1 Embeddable API with Embedded GlassFish Server

To Use the EJB 3.1 Embeddable API with Embedded GlassFish Server

EJB 3.1 Embeddable API Properties

Default Java Persistence Data Source for Embedded GlassFish Server

Index

Using the EJB 3.1 Embeddable API with Embedded GlassFish Server

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

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:

To Use the EJB 3.1 Embeddable API with Embedded GlassFish Server

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

    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.

  2. Configure any required resources.

    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.

  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-install/domains/domain1. This system property applies only to embeddable EJB applications used with Embedded GlassFish Server.

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

EJB 3.1 Embeddable API Properties

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

Property
Default
Description
installation.root
GlassFish Server installation location
instance.root
In order of precedence:
  • glassfish.embedded.tmpdir system property value

  • java.io.tmp system property value

  • as-install/domains/domain1

configuration.file
domain-dir/config/domain.xml
The configuration file.
keep-temporary-files
false
If true, keeps temporary files (exploded EAR file and configuration file) created by the embedded EJB container when Embedded GlassFish Server is stopped.
web.http.port
None
Enables the web container if set. Needed for testing web services in a WAR file. The value is ignored and can be an empty string.
instance.reuse
false
If true, no changes are made to the existing configuration file, and a temporary server instance is not created for the embedded run. Instead, execution happens against the existing server instance. Do not use this option if the reused server instance could be in use by the running GlassFish Server.
skip-client-modules
false
If true, omits modules from the classpath if they are not specified using EJBContainer.MODULES and have a manifest file with a Main-Class attribute.