Skip to main content

Embedded GlassFish Maven Plugin : Deploying multiple applications

Posted by bhavanishankar on March 18, 2012 at 9:45 PM PDT

This blog describes how to configure org.glassfish:maven-embedded-glassfish-plugin for deploying more than one application.

There was a community request for this. Refer:

http://java.net/projects/glassfish/lists/users/archive/2012-02/message/382
http://stackoverflow.com/questions/9280413/maven-embedded-glassfish-plugin-deploying-2-applications

The following pom.xml snippet shows how to configure the plugin to achieve this:

            <plugin>
                <groupId>org.glassfish</groupId>
                <artifactId>maven-embedded-glassfish-plugin</artifactId>
                <version>4.0-SNAPSHOT</version>

                <!-- Plugin level configurations -->
                <configuration>
                    <goalPrefix>glassfish</goalPrefix>
                    <app>target/firstapp.war</app>
                    <port>8080</port>
                    <ports>
                        <https-listener>8181</https-listener>
                    </ports>
                    <name>firstapp</name>
                    <serverID>embedded</serverID>
                </configuration>

                <executions>

                    <!-- Start embedded GlassFish -->
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>

                    <!-- Run some admin commands -->
                    <execution>
                        <id>admin</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>admin</goal>
                        </goals>
                        <configuration>
                            <commands>
                                <param>list-applications</param>
                            </commands>
                        </configuration>
                    </execution>

                    <!-- Perform normal deployment (first application) using plugin level configurations -->
                    <execution>
                        <id>deploy</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>

                    <!-- Deploy second application (using goal specific configurations) -->
                    <execution>
                        <id>deploy2</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                        <configuration>
                            <app>secondapp/secondapp.war</app>
                            <contextRoot>secondapp</contextRoot>
                            <name>secondapp</name>
                            <deploymentParams>
                                <param>--verify=true</param>
                            </deploymentParams>
                        </configuration>
                    </execution>

                    <!-- Undeploy the second application (using goal specific configurations) -->
                    <execution>
                        <id>undeploy</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>undeploy</goal>
                        </goals>
                        <configuration>
                            <name>secondapp</name>
                        </configuration>
                    </execution>

                    <!-- Perform normal undeploy (i.e., first app) using plugin level configurations and stop embedded GlassFish -->
                    <execution>
                        <id>stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>undeploy</goal>
                            <goal>stop</goal>
                        </goals>
                    </execution>

                </executions>
            </plugin>

With 4.0-SNAPSHOT version of the plugin, 'mvn embedd-glassfish:run' is also enhanced to run all the 'admin' goals, and all the 'deploy' goals.

The following devtest should serve more details:

http://java.net/projects/glassfish/sources/svn/show/trunk/main/appserver/tests/embedded/maven-plugin/multipleApps

Checkout the devtest with : svn checkout https://svn.java.net/svn/glassfish~svn/trunk/main/appserver/tests/embedd...

 

Comments

I can't seem to find a good glassfish maven plugin that will ...

I can't seem to find a good glassfish maven plugin that will deploy my artifacts to a remote glassfish server, is that right?

I'm aware of the cargo plugin, but I would like all of the functionality of the maven-glassfish-plugin to work on remote servers. Are you planning that by any chance?

Hi, Thank you for this great improvement. A little ...

Hi,

Thank you for this great improvement. A little contribution would be to deploy a second application using a maven dependency inspite a local directory, it would be useful to use with CI(jenkins, hudson,...)

Lot of thanks,

Marcial Atiénzar

Hi Marcial Ati&eacute;nzar, Thanks for the valuable ...

Hi Marcial Atiénzar,

Thanks for the valuable feedback. Enhancement request is filed @ http://java.net/jira/browse/GLASSFISH-18535

Bhavani