18

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

/pom.xml // 父 pom
 webapp1/pom.xml // 配置为指向父级
 webapp2/pom.xml // webapp1 的对等点并指向父级。

每个 webapps 都引用父 pom,并且它们目前都有一个可以工作的 jetty maven 插件。

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

编辑回答: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”个 webapp。因此,http://localhost:8080/webapp1http://localhost:8080/webapp2可通过一个命令行参数使用。

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

4

1 回答 1

10

编辑:我已经完全编辑了我的第一个答案,因为我对 OP 的期望有了更好的理解。

查看Cargo它是一个瘦包装器,允许您以标准方式操作 Java EE 容器

实际上,在 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>
[...]

如果你想使用 Jetty 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插件参考指南):

<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 并通过简单的方式在其上部署您的 webapps(从包含货物插件配置的项目中运行):

$ mvn cargo:start

我只是不确定这是否可以与父 pom 一起使用(我想知道这是否会导致循环依赖问题)并且我没有对其进行测试。但就个人而言,我会将所有这些东西放在一个专用项目的 pom 中,例如,放在 webapps 的兄弟项目中,而不是放在父 pom 中。我认为这没什么大不了的,恕我直言,这是一个更好的设置,特别是如果您打算使用 cargo 进行集成测试

于 2009-03-12T19:38:56.127 回答