views:

186

answers:

4

I'm trying to configure pom.xml so that it automatically deploys EAR archive to GlassFish application server. I want to attach this operation to the proper maven execution phase. But can't understand which one is dedicated just for this operation? Deploy? Install? Please, help. This is what I'm doing:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>deploy</phase>
            <configuration>
                <tasks>
                    <copy file="${project.build.directory}/${project.build.finalName}.ear" 
                        tofile="${glassfish.home}/domains/domain1/autodeploy"/>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

When I'm doing mvn deploy, maven is trying to deploy my artifacts to repository. This is not what I'm going to accomplish. I feel that the execution phase is wrong..

+1  A: 

It might not be a direct answer to your question, but have a look at the cargo plugin: http://cargo.codehaus.org/

It addresses this exact need (among other things)

Karl Johansson
Looks like this is exactly what I need! Thanks!
Vincenzo
Cargo does allow to interact with a container but this doesn't answer the question at all.
Pascal Thivent
+2  A: 

In addition to scdef's answer, here's a brief example of what using the cargo plugin looks like: http://blank.jasonwhaley.com/2010/03/automated-deployment-with-cargo-drive.html. I personally didn't bind it to a phase, since I don't want deployment to happen on every invocation of maven and didn't intend on writing another pom/profile to handle invoking the plugin.

Additionally, I'd recommend not using maven at all to deploy my applications to stable environments where there are almost always going to be other applications/databases/systems in the environment that need to be altered in addition placing the application in the container. Production almost always falls under this scope. Coordinating a .war/.ear/whatever deployment to a container/server under this context really should be decoupled from actually building your application. Leave deployments like this to external scripts or perhaps a comprehensive tool like Puppet.

whaley
Who else if not `maven` should deploy an application to production application server?
Vincenzo
Something that isn't a tool for building software - there's always something unique about every deployment I've ever seen and the only way to address that imo is with scripts that handle deployment specifically for your environment. Building software and deploying software should be independent activities that *could* be chained together for convenience, but don't have to be.Further, the way people get into the most trouble with maven (and end up hating it) is by using it for things it wasn't meant to do. Coordinating deployments to [production] environments is one of those things.
whaley
I disagree. First, server deployment is a typical build time activity when running integration/functional tests. Second, Maven has phases for that (the integration-test phase and the pre/post phases around it). So both statements are IMO incorrect stated as such. However, deployment to production servers **as part of a build lifecycle** is indeed another story.
Pascal Thivent
I'll agree to your disagreement, as I scoped the term "deployment" as deploying software to a stable environment, and not just a localhost or throwaway deployment for testing (I rarely refer to those as "deployments", personally). Thanks for the comments as it led me to clarify my original answer a bit.
whaley
You're welcome. *I* think your answer is much better now (and you have my +1 now). Do you have any practical experience with Puppet for Java EE deployments by the way?
Pascal Thivent
no practical unfortunately. we were evaluating puppet and were about to start using it at a previous shop before I left. I used puppet briefly and liked what I saw, but stopped after my work no longer resembled 'devops' type stuff.
whaley
+4  A: 

When I'm doing mvn deploy, maven is trying to deploy my artifacts to repository. This is not what I'm going to accomplish. I feel that the execution phase is wrong...

In the Maven lingua, deploy has nothing to do with the deployment to an application server and is not an appropriate phase to bind a plugin doing this kind of work. Here is what we can read about the deploy phase in the Introduction to the Build Lifecycle:

  • deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

But, before I go further with phases, I need to mention that there are several plugins allowing to interact with GF (start/stop/deploy/undeploy/etc) that might do a better job than the AntRun plugin (AntRun might work for trivial use cases but, for example, you might want to wait for the deployment to be done and the application to be in a ready state during the build; for such use cases, you need more advanced control). These candidates are:

Using one or the other really depends on your use case. If you don't plan to deploy on many containers, the GlassFish specific plugins are the most powerful. The beauty of Cargo is that it offers an unified API. But its configuration is less intuitive, especially if you're not used to it.

Now, if you just want to deploy an application during development and don't want the build to interact in any way with the container, binding any of these plugins to a particular phase is not that useful, although some people do deploy their app during package.

However, you might want to run integration/functional tests against a container as part of you build. This is actually a perfectly valid and very common use case and the relevant phases to implement this are:

  • pre-integration-test: perform actions required before integration tests are executed. This may involve things such as setting up the required environment.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run.
  • post-integration-test: perform actions required after integration tests have been executed. This may including cleaning up the environment.

The pre-integration-test phase is typically used to start a container and deploy an application on it. The post-integration-test phase is used to undeploy an application and stop the container.

So I think that deploying to a server can be a typical build activity, there are very valid use cases, and this is well supported by Maven. I don't deploy to my development server (nor to production server) as part of a build though.

See also

Pascal Thivent
A: 

I've implemented that behavior using a copy task with the ant plug-in on maven.

The correct phase for doing this is the package phase.

See http://maven.apache.org/plugins/maven-antrun-plugin/index.html for more details.

Regards.

StudiousJoseph