5

我有一個Java應用程序,它運行在Web容器(Jetty當前)內並通過Web服務響應請求。如何實現Web服務的連續部署

現在我想創建一個機制,它允許儘可能輕鬆地部署(將WAR文件傳輸到服務器,在那裏安裝新版本)應用程序的新版本到最新版本(理想情況下 - 通過運行一些Maven命令)。

我爲我的版本控制使用Beanstalk,他們提供部署支持,但我無法弄清楚如何將其應用於我的方案。

是否有任何關於如何使用Maven(帶或不帶Beanstalk)將Web應用程序部署到Amazon EC2的教程?

更新1(2013年4月10日):魔豆的工作人員建議我使用SSH deployments

更新2(二〇一三年十一月四日23:17 MSK):

我在第一次使用Maven插件貨物的嘗試,我加了下面的東西我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):

我改變有關貨物插件這樣的部分:

<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] 

Update 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> 

然後,我用下面的命令來我的應用程序部署到服務器:

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

請注意,<packaging>必須設置爲war才能使此序列正常工作(否則您可能會收到奇怪的錯誤消息)。

回答

1

請糾正我,如果我錯了。我明白你正在使用Tomcat version 7。爲Tomcat 7Cargo配置應該是如下所示: -

<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>myusername</cargo.remote.username> 
       <cargo.remote.password>mypassword</cargo.remote.password> 
       <cargo.hostname>MY_HOST</cargo.hostname> 
       <cargo.protocol>http</cargo.protocol> 
       <cargo.servlet.port>SERVER_PORT</cargo.servlet.port> 
      </properties> 
     </configuration> 
     <!-- Deployer configuration --> 
     <deployer> 
      <type>remote</type> 
      <deployables> 
       <deployable> 
        <groupId>ru.mycompany</groupId> 
        <artifactId>my-product</artifactId> 
        <type>war</type> 
        <properties> 
         <context>MY_CONTEXT</context> 
        </properties> 
       </deployable> 
      </deployables> 
     </deployer> 
    </configuration> 
</plugin> 

請注意,

  1. <cargo.hostname>是遠程主機名或IP地址。
  2. <cargo.protocol>httphttps
  3. <cargo.servlet.port>是基於<cargo.protocol>remote port,例如, 8080或8443
  4. <context>是在部署Web應用程序時使用的context name

有關更多信息,請參閱Cargo: Tomcat 7.xMaven2 Plugin Reference Guide

我希望這可能有所幫助。

+0

感謝您的回答。我試過了,你可以在上面的「更新3」中看到結果。 – 2013-04-12 18:40:16

+0

如果我錯了,請糾正我。在我回答的時候,更新3使用了tomcat7而不是tomcat7x。 – 2013-04-13 00:56:22

+0

由於StackOverflow法規的限制,我現在不能授予您賞金。請等2小時。 – 2013-04-13 07:43:59

0

正如查理和德米特里早些時候回答的那樣,貨物插件通常是最簡單的方法。 雖然這樣做,但您也可以考慮實際創建EC2實例的方式(如許多情況下,包括開發/測試和生產環境),您希望始終創建新實例(請參閱Martin Fowler關於此的想法http://martinfowler.com/bliki/PhoenixServer.htmlhttp://martinfowler.com/bliki/SnowflakeServer.html

這樣做是拉維羅系統,基本上可以讓你輕鬆地在雲中創建的應用程序的完全成熟的複製品,他們甚至實施了Maven插件的自動化,爲幫助提供一個有趣的解決方案。以一個看看http://www.ravellosystems.com/blog/ravello_maven_plugin/ - 您可以將整個過程與Maven進行端到端的整合 - 從創建環境到部署應用程序,測試它並將其拆除。