代码之家  ›  专栏  ›  技术社区  ›  Nathan Feger

如何从父pom部署多个对等网络应用程序

  •  18
  • Nathan Feger  · 技术社区  · 16 年前

    我有一套我管理的网络应用,我正试图转移到maven。

    /pom.xml            // parent pom
     webapp1/pom.xml    // configured to point to parent
     webapp2/pom.xml    // peer of webapp1 and points to parent.
    

    每个webapps都指向父pom,它们目前都有一个jetty maven插件可以工作。

    我的问题是如何从父pom装载每个WebApp,以便mvn jetty:run在父目录中工作?

    编辑至anwer:Pascal T 问题不在于我尝试从根pom运行命令时出错,而在于我不确定如何配置它。

    例如webapp1/pom。xml 看起来像:

    <project>
    ...
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
      </plugin>
    </plugins>
    ...
    </project>
    

    切换到这个目录并键入mvn jetty:run就可以了,我可以点击: http://localhost:8080/webapp1 .

    但是,我希望成为webapp1的父目录,并从父目录运行所有“n”个webapps。因此 http://localhost:8080/webapp1 http://localhost:8080/webapp2 只提供一个命令行参数。

    顺便说一句,如果答案涉及tomcat插件,那就好了。

    2 回复  |  直到 16 年前
        1
  •  10
  •   Pascal Thivent    16 年前

    编辑 当前位置我已经完全编辑了我的第一个答案,现在我对OP的期望有了更好的理解。

    退房 Cargo , 一个薄包装器,允许您以标准方式操作JavaEE容器 .

    实际上,有一个 tutorial 在Cargo的网站上,演示了如何使用Cargo Maven2插件自动启动/停止容器(可能会在容器启动时部署一些可部署的组件),这就是我所了解的。

    我只是不确定从父目录执行此操作是否可行,以及这是否是一项要求,或者是否可以从另一个目录执行此操作。我稍后再谈这个问题。让我们首先看看Cargo Maven2插件的设置。

    在您的情况下,可以从最低配置开始(使用Jetty 5.x,这是Cargo的默认容器):

    [...]
    <build>
      <plugins>
        <plugin>
          <groupId>org.codehaus.cargo</groupId>
          <artifactId>cargo-maven2-plugin</artifactId>
        </plugin>
      </plugins>
    </build>
    [...]
    

    如果你想使用6号码头。x、 你必须详细说明 <containerId> <type> <container> 要素:

    [...]
    <plugin>
     <groupId>org.codehaus.cargo</groupId>
     <artifactId>cargo-maven2-plugin</artifactId>
     <configuration>
       <container>
         <containerId>jetty6x</containerId>
         <type>embedded</type>
       </container>
     </configuration>
    </plugin>
    [...]
    

    然后,通过定义 可部署 明确地在插件配置中(参考 Maven2 Plugin Reference Guide 有关配置的详细信息):

    <deployables>
      <deployable>
        <groupId>com.mycompany.myproject</groupId>
        <artifactId>myproject-alpha</artifactId>
        <type>war</type>
        <properties>
          <context>optional alpha root context</context>
        </properties>
      </deployable>
      <deployable>
        <groupId>com.mycompany.myproject</groupId>
        <artifactId>myproject-beta</artifactId>
        <type>war</type>
        <properties>
          <context>optional beta root context</context>
        </properties>
      </deployable>
      [...]
    </deployables>
    

    有了这个,你应该能够启动Jetty,并通过一个简单的(从包含cargo插件配置的项目中运行)在其上部署你的WebApp:

    $ mvn cargo:start
    

    我只是不确定这是否适用于父pom(我想知道这是否会导致循环依赖性问题),我没有测试它。但就我个人而言,我会把所有这些东西放在一个专门项目的pom中,例如,放在你的WebApp的兄弟项目中,而不是放在父pom中。我不认为这是一个真正的大问题,这是一个更好的设置,尤其是如果你计划使用货物进行运输 integration testing .

    推荐文章