Oracle GlassFish Server 3.0.1 Embedded Server Guide

ProcedureTo Set Up Your Maven Environment

Setting up your Maven environment enables Maven to download the required embedded GlassFish 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.

Before You Begin

Ensure that Apache Maven is installed.

  1. Identify the Maven plug-in for embedded GlassFish Server.

    Add the following plugin element to your POM file:

    ...
            ...
            <plugins>
                ...
                <plugin>
                    <groupId>org.glassfish</groupId>
                    <version>version</version>
                </plugin>
                ...
            </plugins>
    ...
    version

    The version to use. The version of the final promoted build for this release is 3.0-74b.

  2. 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 GlassFish Server.

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

    The goal to use. See Maven Goals for Embedded GlassFish Server.

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

Example 12 POM File for Configuring Maven to Use Embedded GlassFish Server

This example shows a POM file for configuring Maven to use embedded GlassFish 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>