如何实现Web服务的持续部署

2024-01-02

我有一个 Java 应用程序,它在 Web 容器(目前是 Jetty)内运行,并通过 Web 服务响应请求。

现在我想创建一种机制,允许尽可能轻松地将应用程序的新版本部署(将 WAR 文件传输到服务器,在那里安装新版本)到 Amazon EC2 实例(理想情况下 - 通过运行一些 Maven 命令) 。

我在用着豆茎 http://beanstalkapp.com/对于我的版本控制,他们提供部署支持,但我不知道如何将其应用到我的场景中。

是否有关于如何使用 Maven(带或不带 Beanstalk)将 Web 应用程序部署到 Amazon EC2 的教程?

更新 1(2013 年 4 月 10 日):Beanstalk 工作人员推荐我使用SSH 部署 http://support.beanstalkapp.com/customer/portal/articles/361135-how-do-i-setup-ssh-deployments-.

更新 2(2013 年 4 月 11 日 23:17 MSK):

在我第一次尝试使用 Maven Cargo 插件时,我将以下内容添加到我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    [...]
    <build>
    [...]    
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>Heaven7</containerId>
                        <type>remote</type>
                    </container>
                    <configuration>
                        <type>runtime</type>
                        <properties>
                            <cargo.remote.username>myusername</cargo.remote.username>
                            <cargo.remote.password>mypassword</cargo.remote.password>
                        </properties>
                    </configuration>

                    <!-- Deployer configuration -->
                    <deployer>
                        <type>remote</type>
                    </deployer>

                    <deployables>
                        <deployable>
                            <groupId>ru.mycompany</groupId>
                            <artifactId>my-product</artifactId>
                            <type>war</type>
                        </deployable>
                    </deployables>
                </configuration>
            </plugin>
        </plugins>
    </build>
    [...]
</project>

然后我跑了mvn cargo:deploy并得到以下输出:

[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.3.3:dep
oy (default-cli) on project [...]: Execution default-cli of goal org.codeh
us.cargo:cargo-maven2-plugin:1.3.3:deploy failed: Cannot create configuration.
here's no registered configuration for the parameters (container [id = [Heaven7
, type = [remote]], configuration type [runtime]). Actually there are no valid
ypes registered for this configuration. Maybe you've made a mistake spelling it

2个问题:

  1. 我该如何修复它?
  2. 在哪里可以指定 Tomcat 容器的地址?

更新 3(2013 年 4 月 12 日 22:36 MSK):

我更改了与 Cargo 插件相关的部分,如下所示:

    <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.3.3</version>
        <configuration>
            <container>
                <containerId>tomcat7</containerId>
                <type>remote</type>
            </container>
            <configuration>
                <type>runtime</type>
                <properties>
                    <cargo.remote.username>myuser</cargo.remote.username>
                    <cargo.remote.password>mypassword</cargo.remote.password>
                    <cargo.hostname>ec2-NN-NNN-NN-NN.compute-1.amazonaws.com</cargo.hostname>
                    <cargo.protocol>http</cargo.protocol>
                    <cargo.servlet.port>8080</cargo.servlet.port>
                </properties>
            </configuration>

            <!-- Deployer configuration -->
            <deployer>
                <type>remote</type>
            </deployer>
            <deployables>
                <deployable>
                    <groupId>ru.mycompany</groupId>
                    <artifactId>myproduct</artifactId>
                    <type>war</type>
                </deployable>
            </deployables>

        </configuration>
    </plugin>
</plugins>

然后我执行了mvn cargo:deploy并得到这个输出:

[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.3.3:depl
oyer-deploy (default-cli) on project ccp-server: Execution default-cli of goal o
rg.codehaus.cargo:cargo-maven2-plugin:1.3.3:deployer-deploy failed: Cannot creat
e configuration. There's no registered configuration for the parameters (contain
er [id = [tomcat7], type = [remote]], configuration type [runtime]). Actually th
ere are no valid types registered for this configuration. Maybe you've made a mi
stake spelling it? -> [Help 1]

更新4(2013年4月12日23:12):

我变了pom.xml再次致:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.3.3</version>
    <configuration>
        <container>
            <containerId>tomcat7x</containerId>
            <type>remote</type>
        </container>
        <configuration>
            <type>runtime</type>
            <properties>
                <cargo.remote.username>myuser</cargo.remote.username>
                <cargo.remote.password>mypassword</cargo.remote.password>
                <cargo.hostname>ec2-NN-NNN-NN-NN.compute-1.amazonaws.com</cargo.hostname>
                <cargo.protocol>http</cargo.protocol>
                <cargo.servlet.port>8080</cargo.servlet.port>
            </properties>
        </configuration>

        <!-- Deployer configuration -->
        <deployer>
            <type>remote</type>
        </deployer>
        <deployables>
            <deployable>
                <groupId>ru.mycompany</groupId>
                <artifactId>myproduct</artifactId>
                <type>war</type>
            </deployable>
        </deployables>

    </configuration>
</plugin>

然后,我使用以下命令将应用程序部署到服务器:

  1. mvn clean
  2. mvn install
  3. mvn cargo:deploy

请注意<packaging>必须设置为war为了使这个序列正常工作(否则你可能会收到奇怪的错误消息)。


你可以使用货物 Maven 插件 http://cargo.codehaus.org/Maven2+plugin部署在远程服务器上。有关 Tomcat 服务器上的远程部署,请参阅此示例:Maven:如何将 WAR 文件部署到远程 Tomcat 服务器? https://stackoverflow.com/questions/8422802/maven-how-do-i-deploy-my-war-file-to-a-remote-tomcat-server

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何实现Web服务的持续部署 的相关文章

随机推荐