How to run the project after building with maven

You have to first tell Maven to build the WAR, check out this plugin for that: http://maven.apache.org/plugins/maven-war-plugin/.

Then you need to tell maven how to deploy to glassfish, you can either configure a Maven execution plugin to do this (see here: https://www.mojohaus.org/exec-maven-plugin/). Or you can look around for a custom plugin devoted to integrating maven with glassfish. This one looks promising, but I have not used it: http://maven-glassfish-plugin.java.net/.

Maven provides a lot of basic functionality out of the box, but most of the cooler stuff with build automation is done through plugins.

Update

Just updating to add a very simple Pom that will do a auto-deployment. Note: if you just run a "mvn clean install", with the packaging set to 'war', maven will build the .war file for you and place it in the target/ folder. You can take this and deploy it to glassfish manually if you just want to get started.

Below is part of a very simple pom that uses the Maven execution plugin to auto-deploy to glassfish as a function of the build:

<build>
  <plugins>
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
        <execution>
        <goals>
              <goal>exec</goal>
        </goals>
        <phase>install</phase>
        </execution>
    </executions>
    <configuration>
        <executable>${path-to-asadmin-util}</executable>
        <arguments>
            <argument>deploy</argument>
            <argument>--user=${username}]</argument>
            <argument>--passwordfile=${password-file}</argument>
            <argument>--host=localhost</argument>
            <argument>--port=4848</argument>
            <argument>target/${project.name}</argument>
        </arguments>
    </configuration>
 </plugin>
 </plugins>
 </build>

This basically just calls the deploy command on the glassfish asadmin utility[1]. You need to fill in the following variables:

  • ${path-to-asadmin-util} --> this is the path to your asadmin utility (normally in the glassfish_home/bin)
  • ${username} --> glassfish admin username
  • ${password-file} --> password file for logging into glassfish admin[2]
  • ${project.name} --> name of your war

If you want to get more complicated I suggest taking a look at this thread: GlassFish v3 and glassfish-maven-plugin (Mac).

[1] - http://docs.oracle.com/cd/E18930_01/html/821-2433/deploy-1.html#SJSASEEREFMANdeploy-1

[2] - http://docs.oracle.com/cd/E18930_01/html/821-2435/ghgrp.html#ghytn


Additonnaly, you should have a glance at this StackOverflow thread, dealing with maven deployement in glassifsh : https://stackoverflow.com/a/1836691/1047365.

For further understanding of Maven, you should REALLY read this (free) book : http://www.sonatype.com/books/mvnref-book/reference/. This is THE reference for Maven.

We can explain you what Maven is doing, producing, etc ... but Sonatype made a great work and you'll probably learn more reading it than we could ever do !

Regards.