The EJB 3.1 Embeddable API is designed for unit testing of EJB modules. You must use this API with a pre-installed, nonembedded GlassFish Server instance. However, you can take advantage of the embedded GlassFish Server's ease of use by referencing the nonembedded GlassFish Server instance with the glassfish-embedded-static-shell.jar file.
Embedded GlassFish Server is not related to the EJB 3.1 Embeddable API, but you can use these APIs together.
The Maven plug-in does not apply to embeddable EJB applications. However, you can use Maven with the POM file shown in Using Maven with the EJB 3.1 Embeddable API and Embedded GlassFish Server.
To specify GlassFish 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.
Configure any required resources.
For more information about configuring resources, see the Administration Console Online Help or Part III, Resources and Services Administration, in Oracle GlassFish Server 3.0.1 Administration Guide. The jdbc/__default Java DB database is preconfigured with all distributions of GlassFish Server.
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.
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 nonembedded GlassFish Server.
Close the EJB container properly to release all acquired resources and threads.
When using Maven with the EJB 3.1 Embeddable API and Embedded GlassFish Server, you cannot use the features of the Maven plug-in. You must start and stop Embedded GlassFish Server manually or programmatically outside of Maven.
This example shows a POM file for configuring Maven to use the EJB 3.1 Embeddable API with Embedded GlassFish Server.
<!-- Line breaks in the following element are for readability purposes only --> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.glassfish</groupId> <artifactId>maven-glassfish-plugin-tester</artifactId> <version>3.0-74b</version> <name>Maven test</name> <dependencies> <dependency> <groupId>org.glassfish.extras</groupId> <artifactId>glassfish-embedded-all</artifactId> <version>3.0</version> </dependency> <!-- The javaee-api is stripped of any code and is just used to compile your application. The scope provided in Maven means that it is used for compiling, but is also available when testing. For this reason, the javaee-api needs to be below the embedded Glassfish dependency. The javaee-api can actually be omitted when the embedded Glassfish dependency is included, but to keep your project Java-EE 6 rather than GlassFish 3, specification is important. --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> </dependencies> <pluginRepositories> <pluginRepository> <id>maven2-repository.dev.java.net</id> <name>Java.net Repository for Maven</name> <url>http://download.java.net/maven/glassfish/</url> </pluginRepository> </pluginRepositories> </project>