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

发布于 2024-09-11 00:46:31 字数 897 浏览 2 评论 0 原文

我正在尝试配置 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 正在尝试将我的工件部署到存储库。这不是我要完成的任务。我感觉执行阶段是错误的..

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鲸落 2024-09-18 00:46:31

当我执行mvn部署时,maven正在尝试将我的工件部署到存储库。这不是我要完成的任务。我感觉执行阶段不对...

在 Maven 语言中,deploy 与部署到应用程序服务器无关,并且不是绑定执行此类工作的插件的适当阶段。以下是我们可以在 deploy 阶段的内容"nofollow noreferrer">构建生命周期简介

  • 部署 - 在集成或发布环境中完成,将最终包复制到远程存储库,以便与其他开发人员和项目共享。

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

使用一个或其他确实取决于您的用例。如果您不打算在许多容器上部署,GlassFish 特定的插件是最强大的。 Cargo 的美妙之处在于它提供了统一的 API。但它的配置不太直观,特别是如果您不习惯的话。

现在,如果您只是想要在开发期间部署应用程序,并且不希望构建以任何方式与容器交互,请将这些插件中的任何一个绑定到特定的尽管有些人确实在打包期间部署他们的应用程序,但阶段并不是那么有用。

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

  • pre-integration-test:执行集成前所需的操作
    执行测试。这可能涉及
    诸如设置所需的东西
    环境。
  • integration-test:如有必要,处理包并将其部署到
    集成测试的环境
    可以运行。
  • post-integration-test:执行集成后所需的操作
    测试已经执行。这可能
    包括清理环境。

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

所以我认为部署到服务器可以是一个典型的构建活动,有非常有效的用例,并且 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...

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

檐上三寸雪 2024-09-18 00:46:31

除了 scdef 的答案之外,这里还有一个使用货物插件的简短示例: http://blank.jasonwhaley.com/2010/03/automated-deployment-with-cargo-drive.html。我个人没有将它绑定到一个阶段,因为我不希望每次调用 Maven 时都进行部署,并且不打算编写另一个 pom/profile 来处理插件的调用。

此外,我建议根本不要使用 Maven 将我的应用程序部署到稳定的环境,在稳定的环境中,除了将应用程序放置在容器中之外,环境中几乎总是存在其他应用程序/数据库/系统需要更改。生产几乎总是属于这个范围。在这种情况下协调 .war/.ear/whatever 部署到容器/服务器确实应该与实际构建应用程序脱钩。将这样的部署留给外部脚本或者像 Puppet 这样的综合工具。

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.

偷得浮生 2024-09-18 00:46:31

它可能不是您问题的直接答案,但请查看一下货物插件: http://cargo.codehaus .org/

它解决了这个确切的需求(除其他外)

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)

若水微香 2024-09-18 00:46:31

我已经使用 Maven 上的 ant 插件使用复制任务来实现该行为。

执行此操作的正确阶段是打包阶段。

请参阅 http://maven.apache.org/plugins/maven-antrun -plugin/index.html 了解更多详细信息。

问候。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文