If you are using Apache Maven, the plug-in for embedded Enterprise Server simplifies the testing of applications. This plug-in enables you to build and start an unpackaged application with a single Maven goal.
Testing applications with the Maven plug-in involves the following tasks:
Predefined Maven goals for embedded Enterprise Server are described in Maven Goals for Embedded Enterprise Server.
Setting up your Maven environment enables Maven to download the required embedded Enterprise Server distribution file when you build your project. Setting up your Maven environment also identifies the plug-in that enables you to build and start an unpackaged application with a single Maven goal.
Ensure that Apache Maven is installed.
Identify the Maven plug-in for embedded Enterprise Server.
Add the following plugin element to your POM file:
... <plugins> ... <plugin> <groupId>org.glassfish</groupId> <version>version</version> ... </plugin> ... </plugins> ...
The version to use. The version of the final promoted build for this release is 3.0-74b.
Configure the embedded-glassfish goal prefix, the application name, and other standard settings.
Add the following configuration element to your POM file:
... <plugins> ... <plugin> ... <configuration> <goalPrefix>embedded-glassfish</goalPrefix> ... <app>test.war</app> <port>8080</port> <contextRoot>test</contextRoot> <autoDelete>true</autoDelete> ... </configuration> ... </plugin> ... </plugins> ...
In the app parameter, substitute the archive file or directory for your application. The optional port, contextRoot, and autoDelete parameters show example values. For details, see Maven Goals for Embedded Enterprise Server.
Configure Maven goals.
Add execution elements to your POM file:
... <plugins> ... <plugin> ... <executions> <execution> <phase>install</phase> <goals> <goal>goal</goal> </goals> </execution> </executions> ... </plugin> ... </plugins> ...
The goal to use. See Maven Goals for Embedded Enterprise Server.
Configure the repository.
Add the following repository element to your POM file:
<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>
This example shows a POM file for configuring Maven to use embedded Enterprise Server.
<?xml version="1.0" encoding="UTF-8"?> Line breaks in the following element are for readability purposes only <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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> <build> <plugins> <plugin> <groupId>org.glassfish</groupId> <artifactId>maven-embedded-glassfish-plugin</artifactId> <version>3.0-74b</version> <configuration> <goalPrefix>embedded-glassfish</goalPrefix> <app>test.war</app> <port>8080</port> <contextRoot>test</contextRoot> <autoDelete>true</autoDelete> </configuration> <executions> <execution> <phase>install</phase> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <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>
If you are using Maven to manage the development of your application, you can use a Maven goal to build and start the application in embedded Enterprise Server.
Ensure that your Maven environment is configured.
Include the path to the Maven executable file mvn in your path statement.
Ensure that the JAVA_HOME environment variable is defined.
Create a directory for the Maven project for your application.
Copy to your project directory the POM file that you created in To Set Up Your Maven Environment.
Run the following command in your project directory:
mvn install |
This command performs the following actions:
Installs the Maven repository in a directory named .m2 under your home directory.
Starts embedded Enterprise Server.
Deploys your application.
The application continues to run in embedded Enterprise Server until embedded Enterprise Server is stopped.
Change to the root directory of the Maven project for your application.
Run the Maven goal to stop the application in embedded Enterprise Server.
mvn embedded-glassfish:stop |
This runs the stop method of the Server object and any other methods that are required to shut down the server in an orderly fashion. See Stopping an Embedded Enterprise Server From an Application.
An application that was built and started from Maven continues to run in embedded Enterprise Server until embedded Enterprise Server is stopped. While the application is running, you can test changes to the application by redeploying it.
You can use the following Maven goals to test your applications with embedded Enterprise Server:
This goal starts the server and deploys an application. You can redeploy if you change the application. The application can be a packaged archive or a directory that contains an exploded application. You can set the parameters described in the following table.
Table 3 embedded-glassfish:run Parameters
Parameter |
Default |
Description |
---|---|---|
maven |
(optional) The ID of the server to start. |
|
all |
(optional) The container to start: web, ejb, jpa, or all. |
|
In order of precedence:
|
(optional) The Installation Root Directory. |
|
as-installdomains/domain1 |
(optional) The Instance Root Directory |
|
instance-dirconfig/domain.xml |
(optional) The configuration file. |
|
None. Must be set explicitly or defined in the configuration file. |
(optional) The HTTP port. |
|
None. |
The archive file or directory for the application to be deployed. |
|
In order of precedence:
For more information, see Naming Standards in Sun GlassFish Enterprise Server v3 Application Deployment Guide. |
(optional) The name of the application. |
|
The name of the application. |
(optional) The context root of the application. |
|
false |
(optional) If true, JSP pages are precompiled during deployment. |
|
Value of the create-tables-at-deploy attribute in sun-ejb-jar.xml. |
(optional) If true, creates database tables during deployment for beans that are automatically mapped by the EJBTM container. |
|
false |
(optional) If true, deletes the contents of the Instance Root Directory when the server is stopped. Caution – Do not set autoDelete to true if you are using installRoot to refer to a preexisting Enterprise Server installation. |
This goal starts the server. You can set the parameters described in the following table.
Table 4 embedded-glassfish:start Parameters
Parameter |
Default |
Description |
---|---|---|
maven |
(optional) The ID of the server to start. |
|
all |
(optional) The container to start: web, ejb, jpa, or all. |
|
In order of precedence:
|
(optional) The Installation Root Directory. |
|
as-installdomains/domain1 |
(optional) The Instance Root Directory |
|
instance-dirconfig/domain.xml |
(optional) The configuration file. |
|
None. Must be set explicitly or defined in the configuration file. |
(optional) The HTTP port. |
|
false |
(optional) If true, deletes the contents of the Instance Root Directory when the server is stopped. Caution – Do not set autoDelete to true if you are using installRoot to refer to a preexisting Enterprise Server installation. |
This goal deploys an application. You can redeploy if you change the application. The application can be a packaged archive or a directory that contains an exploded application. You can set the parameters described in the following table.
Table 5 embedded-glassfish:deploy Parameters
Parameter |
Default |
Description |
---|---|---|
None. |
The archive file or directory for the application to be deployed. |
|
In order of precedence:
For more information, see Naming Standards in Sun GlassFish Enterprise Server v3 Application Deployment Guide. |
(optional) The name of the application. |
|
The name of the application. |
(optional) The context root of the application. |
|
false |
(optional) If true, JSP pages are precompiled during deployment. |
|
Value of the create-tables-at-deploy attribute in sun-ejb-jar.xml. |
(optional) If true, creates database tables during deployment for beans that are automatically mapped by the EJB container. |
This goal undeploys an application. You can set the parameters described in the following table.
Table 6 embedded-glassfish:undeploy Parameters
This goal stops the server. You can set the parameters described in the following table.
Table 7 embedded-glassfish:stop Parameters
Parameter |
Default |
Description |
---|---|---|
maven |
(optional) The ID of the server to stop. |