java – 部署到应用程序服务器的正确maven2阶段是什么?

我正在尝试配置pom.xml,以便它自动将EAR存档部署到GlassFish应用程序服务器.我想将此操作附加到正确的maven执行阶段.但是无法理解哪一个专门用于此操作?部署?安装?请帮忙.这就是我正在做的事情:
<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>

当我正在进行mvn deploy时,maven正在尝试将我的工件部署到存储库.这不是我要完成的事情.我觉得执行阶段是错误的..

解决方法

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…

在Maven语言中,deploy与部署到应用程序服务器无关,也不是绑定执行此类工作的插件的适当阶段.以下是我们可以阅读的有关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.

但是,在我进一步讨论阶段之前,我需要提一下,有几个插件允许与GF(启动/停止/部署/取消部署/等)进行交互,这可能比AntRun插件做得更好(AntRun可能适用于琐碎的工作用例,但是,例如,您可能希望等待部署完成并且应用程序在构建期间处于就绪状态;对于此类用例,您需要更高级的控制).这些候选人是:

> Maven Glassfish Plugin:这是一个GlassFish特定的插件,可以与本地或远程GlassFish安装一起使用.
> Maven Embedded GlassFish Plugin:这是一个运行嵌入式GlassFish的GlassFish特定插件.适合便携式构建.
> Maven Cargo Plugin:这是一个容器不可知的插件,现在支持GlassFish 3.

使用其中一个确实取决于您的用例.如果您不打算在许多容器上部署,则GlassFish特定插件是最强大的. Cargo的魅力在于它提供了统一的API.但它的配置不太直观,特别是如果你不习惯它.

现在,如果您只是想在开发期间部署应用程序并且不希望构建以任何方式与容器进行交互,那么将任何这些插件绑定到特定阶段并不是那么有用,尽管有些人在部署过程中部署了应用程序.包.

但是,您可能希望在构建过程中对容器运行集成/功能测试.这实际上是一个非常有效且非常常见的用例,实现这一点的相关阶段是:

  • 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.

预集成测试阶段通常用于启动容器并在其上部署应用程序.集成后测试阶段用于取消部署应用程序并停止容器.

所以我认为部署到服务器可以是一个典型的构建活动,有非常有效的用例,Maven很好地支持这一点.我不是作为构建的一部分部署到我的开发服务器(也不是生产服务器).

也可以看看

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

相关文章

应用场景 C端用户提交工单、工单创建完成之后、会发布一条工...
线程类,设置有一个公共资源 package cn.org.chris.concurre...
Java中的数字(带有0前缀和字符串)
在Java 9中使用JLink的目的是什么?
Java Stream API Filter(过滤器)
在Java中找到正数和负数数组元素的数量