我有一个 Java 应用程序,它在 Web 容器(目前是 Jetty)中运行并通过 Web 服务响应请求。
现在我想创建一种机制,允许尽可能轻松地将应用程序的新版本部署(将 WAR 文件传输到服务器,在那里安装新版本)到 Amazon EC2 实例(理想情况下 - 通过运行一些 Maven 命令) .
我使用Beanstalk进行版本控制,它们提供部署支持,但我不知道如何将它应用到我的场景中。
是否有关于如何使用 Maven(有或没有 Beanstalk)将 Web 应用程序部署到 Amazon EC2 的教程?
更新 1 (10.04.2013): Beanstalk 工作人员建议我使用SSH 部署。
更新 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
才能使此序列起作用(否则您可能会收到奇怪的错误消息)。