Java – what is the right maven2 phase to deploy to an application server?

I'm trying to configure POM XML so that it automatically deploys the ear archive to the GlassFish application server I want to attach this operation to the correct Maven execution phase But I can't understand which one is dedicated to this operation? Deployment? Installation? Please help. That's 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>

While I was doing MVN deploy, Maven was trying to deploy my artifacts to the repository This is not what I want to accomplish I think the execution phase is wrong

Solution

In maven, deploy has nothing to do with deploying to an application server, nor is it the appropriate stage to bind plug-ins that perform such work The following is what we can read about the deployment phase in the introduction to the build lifecycle:

However, before I further discuss the phase, I need to mention that there are several plug-ins that allow interaction with GF (start / stop / deploy / undeploy / etc.), This may be better than the antrun plug-in (antrun may be suitable for trivial work cases, but, for example, you may want to wait for deployment to complete and the application is ready during construction; for such cases, you need more advanced control) These candidates are:

>Maven GlassFish plugin: This is a GlassFish specific plug-in that can be used with local or remote GlassFish installations. > Maven embedded GlassFish plugin: This is a GlassFish specific plug-in running embedded GlassFish Suitable for portable construction. > Maven cargo plugin: This is a container agnostic plug-in that now supports GlassFish 3

Using one of these really depends on your use case GlassFish specific plug-ins are the most powerful if you are not going to deploy on many containers The charm of cargo is that it provides a unified API But its configuration is not very intuitive, especially if you are not used to it

Now, if you just want to deploy the application during development and don't want the build to interact with the container in any way, binding any of these plug-ins to a specific phase is not so useful, although some people deploy the application during the deployment process Bag

However, you may want to run integration / functional tests on the container during the build process This is actually a very effective and common use case. The relevant stages to achieve this are:

The pre - integration test phase is usually used to start the container and deploy applications on it The post - integration test phase is used to undeploy the application and stop the container

So I think deploying to the server can be a typical build activity with very effective use cases, which Maven supports very well I did not deploy to my development server (nor production server) as part of the build

You can also have a look

> Maven Embedded Glassfish Plugin > Which Maven Glassfish plugin to use?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>