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

标签 maven amazon-web-services amazon-ec2 maven-3 continuous-deployment

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

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

我正在使用 Beanstalk对于我的版本控制,他们提供部署支持,但我不知道如何将它应用到我的场景中。

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

更新 1 (10.04.2013): Beanstalk 工作人员推荐我使用 SSH deployments .

更新 2 (11.04.2013 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个问题:
  • 我该如何解决?
  • 我在哪里可以指定我的 Tomcat 容器的地址?

  • 更新 3 (12.04.2013 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 (12.04.2013 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>
    

    然后,我使用以下命令将我的应用程序部署到服务器:
  • mvn clean
  • mvn install
  • mvn cargo:deploy

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

    最佳答案

    您可以使用 cargo maven plugin部署在远程服务器上。有关 Tomcat 服务器上的远程部署,请参见此示例:Maven: How do I deploy my WAR file to a remote Tomcat server?

    关于maven - 如何实现 Web 服务的持续部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15922311/

    相关文章:

    maven - 为什么 Maven 程序集在 SBT 程序集发现冲突时工作

    java - 创建 Restful 客户端后在 Maven 中出现异常

    ubuntu - RabbitMQ On Ubuntu 14.04 服务器配置

    amazon-web-services - AWS 上的聊天应用程序 : EC2 (eJabberd XMPP) vs RDS (Relational Database) vs other options?

    amazon-ec2 - EC2/Rackspace/Eucalyptus/OpenStack 上的库/开发平台

    maven - 您如何管理项目的依赖项(库)的许可证?

    java - 如何使用Maven项目在JAR中添加测试类

    amazon-web-services - cnf-init 在 ubuntu ami 上抛出 Python 错误

    javascript从aws lambda查询dynamodb中的最后一项

    javascript - 无法正确使用 fetch 在 S3 上放置文件