Maven Embedded GlassFish Plugin
A Maven plugin for managing Embedded GlassFish server instances during the build lifecycle.
Supports Eclipse GlassFish 6, 7, 8, or newer.
Quick Start
Run your project’s main artifact on Embedded GlassFish directly from command line without modifying your pom.xml:
mvn org.glassfish.embedded:embedded-glassfish-maven-plugin:8.0:run -Dglassfish.version=8.0.1
Or add the plugin to your pom.xml:
<plugin>
<groupId>org.glassfish.embedded</groupId>
<artifactId>embedded-glassfish-maven-plugin</artifactId>
<version>8.0</version>
<configuration>
<glassfish.version>8.0.1</glassfish.version>
</configuration>
</plugin>
Start the server with your application and wait until it stops:
mvn embedded-glassfish:run
Basic Usage
Command Line
Start server in background:
mvn embedded-glassfish:start
Deploy application:
mvn embedded-glassfish:deploy
Stop server:
mvn embedded-glassfish:stop
Integration Testing
<plugin>
<groupId>org.glassfish.embedded</groupId>
<artifactId>embedded-glassfish-maven-plugin</artifactId>
<version>7.0</version>
<executions>
<execution>
<id>start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>stop-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>undeploy</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Goals Overview
Goal |
Description |
Default Phase |
Starts server, deploys apps, and runs interactively |
none |
|
Starts an Embedded GlassFish server |
pre-integration-test |
|
Stops the Embedded GlassFish server |
post-integration-test |
|
Deploys an application to the server |
pre-integration-test |
|
Undeploys an application from the server |
post-integration-test |
|
Executes admin commands |
pre-integration-test |
Configuration
Basic Configuration
<plugin>
<groupId>org.glassfish.embedded</groupId>
<artifactId>embedded-glassfish-maven-plugin</artifactId>
<version>7.0</version>
<configuration>
<port>8080</port>
<app>${project.build.directory}/${project.build.finalName}.war</app>
</configuration>
</plugin>
-
port - HTTP port number for the server (default: 8080)
-
app - Path to the application artifact to deploy (default: main artifact)
Automatic Artifact Deployment
The plugin automatically detects and deploys your project’s main artifact without requiring explicit configuration:
<plugin>
<groupId>org.glassfish.embedded</groupId>
<artifactId>embedded-glassfish-maven-plugin</artifactId>
<version>7.0</version>
<configuration>
<!-- Main artifact automatically deployed if no <app> parameter specified -->
</configuration>
</plugin>
Note: Currently assumes WAR packaging. For other artifact types, specify the app parameter explicitly.
Admin Commands
Execute administrative commands on the running server:
<plugin>
<groupId>org.glassfish.embedded</groupId>
<artifactId>embedded-glassfish-maven-plugin</artifactId>
<version>7.0</version>
<configuration>
<commands>
<command>set configs.config.server-config.network-config.protocols.protocol.http-listener.http.websockets-support-enabled=true</command>
<command>create-jdbc-resource --connectionpoolid mypool jdbc/myresource</command>
</commands>
</configuration>
</plugin>
Command line usage:
mvn embedded-glassfish:admin -Dcommands="set server.monitoring-service.module-monitoring-levels.web-container=HIGH"
Configuration Reference
Server Configuration
-
configFile - Custom domain configuration file
-
glassfish.version - GlassFish version to use (default: 8.0.0)
-
port - HTTP port number (default: 8080)
-
ports - Map of port configurations
-
serverID - Server identifier (default: "maven")
Goal Reference
run
Starts the server, deploys the project’s WAR artifact by default, and waits for user input. Press Enter to redeploy, type X to undeploy and exit.
A different artifact can be specified via the app configuration parameter.
Default Phase: none (manual execution)
Example:
mvn embedded-glassfish:run
<!-- Deploy a specific artifact instead of the default WAR -->
<configuration>
<app>${project.build.directory}/myapp.war</app>
</configuration>
start
Starts an Embedded GlassFish server with the configured parameters.
Default Phase: pre-integration-test
Example:
mvn embedded-glassfish:start
stop
Stops the Embedded GlassFish server and cleans up resources.
Default Phase: post-integration-test
Example:
mvn embedded-glassfish:stop
deploy
Deploys an application to the running Embedded GlassFish server.
Default Phase: pre-integration-test
Configuration: * app - Application path (auto-detects if not specified) * name - Application name (default: "myapp") * contextRoot - Web application context root * deploymentParams - Raw asadmin deploy parameters, for options not covered by the above (e.g. --precompilejsp=true, --createtables=true)
<configuration>
<deploymentParams>
<param>--contextroot=greetings</param>
<param>--name=myapp</param>
<param>--precompilejsp=true</param>
</deploymentParams>
</configuration>
Example:
mvn embedded-glassfish:deploy -Dapp=target/myapp.war
Advanced Usage
Forked JVM Mode
By default, the start and run goals launch GlassFish in a forked JVM — a separate process isolated from the Maven JVM. This avoids classloader conflicts and JVM option interference between Maven and GlassFish.
When start forks GlassFish, subsequent goals (deploy, undeploy, admin, stop) automatically detect the forked process and communicate with it — no extra configuration needed.
To pass additional JVM arguments to the forked GlassFish process, use vmArgs in pom.xml:
<configuration>
<vmArgs>
<vmArg>-Xmx512m</vmArg>
<vmArg>-Dmy.property=value</vmArg>
</vmArgs>
</configuration>
Or via command line using glassfish.vm.args (space-separated):
mvn embedded-glassfish:start -Dglassfish.vm.args="-Xmx512m -Dmy.property=value"
Both can be used at the same time — arguments are merged.
To run GlassFish in-process instead:
mvn embedded-glassfish:start -Dglassfish.fork=false
mvn embedded-glassfish:run -Dglassfish.fork=false
Or in pom.xml:
<configuration>
<fork>false</fork>
</configuration>
Non-interactive run mode
The run goal normally waits for user input. Set stop=true to skip the interactive loop — GlassFish starts, deploys all apps, then immediately undeploys and stops. Useful for automated integration tests:
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<stop>true</stop>
</configuration>
</execution>
Or via command line:
mvn embedded-glassfish:run -Dglassfish.run.stop=true