我有一个 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个问题:
- 我该如何修复它?
- 在哪里可以指定 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>
然后,我使用以下命令将应用程序部署到服务器:
mvn clean
mvn install
mvn cargo:deploy
请注意<packaging>
必须设置为war
为了使这个序列正常工作(否则你可能会收到奇怪的错误消息)。