我有一个 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个问题:
更新 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/