6

I am new to maven. So I have a project with pom.xml file. So I ran that with maven and the build was successful. I have glassfish. Glassfish is already running separately. So now what is the next step to run the project with Glassfish? My IDE is eclipse.

Amicable
  • 3,115
  • 3
  • 49
  • 77
Sara
  • 2,417
  • 7
  • 35
  • 52

3 Answers3

8

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

Andrew Keeton
  • 22,195
  • 6
  • 45
  • 72
Paul Cichonski
  • 388
  • 1
  • 6
  • Hi Paul I am confused. I am new to maven so forgive me if it is trivial. So what does mvn compile do when I run pom.xml with it? Does it create a ear package? If so then where does this package go so that I can deploy it to glassfish. Tnx. – Sara Jun 08 '12 at 22:56
  • Added a bit of a pom that might get you started. There are a few different ways to do this. – Paul Cichonski Jun 09 '12 at 14:40
  • Sara, just re-read your comment...if you want to do an EAR deployment it is a bit more involved. Are you trying to deploy an EAR or a WAR? – Paul Cichonski Jun 09 '12 at 14:43
  • Thanks a lot for your time. I am trying to deploy ear package to Glassfish. I have the pom.xml ready from the previous programmer. I ll go through the links you sent me today. – Sara Jun 09 '12 at 16:49
  • Jean the company doesn't let me to share it :(. So should I find the directory from POM? Okay today I ll try to understand maven more deeply. Tnx. – Sara Jun 09 '12 at 16:50
  • @PaulCichonski Could you have a look at my question, I tried what you suggested here but maven is failing me. Thanks in advance. My question is: http://stackoverflow.com/questions/16528234/how-to-use-maven-exec-to-run-asadmin-deploy – Henrique Ordine May 13 '13 at 18:01
3

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.

Community
  • 1
  • 1
Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
0

I found this tutorial useful: http://tshikatshikaaa.blogspot.com/2012/05/introduction-to-maven-concepts-crash.html

Sara
  • 2,417
  • 7
  • 35
  • 52