如何从父Pom部署多个对等Web应用程序 [英] How do I deploy multiple peer webapps from a parent pom

查看:120
本文介绍了如何从父Pom部署多个对等Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我管理着一组要尝试迁移到Maven的Web应用程序.

I have a set of web apps that I manage that I am trying to move to maven.


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

每个Web应用程序都引用父pom,并且它们当前都具有可运行的jetty maven插件.

each of the webapps refers to the parent pom, and they both currently have a jetty maven plugin that works.

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

My question is how do I mount each of the webapps from the parent pom such that mvn jetty:run works in the parent directory?

修改以回答:Pascal T 问题不仅仅在于尝试从root pom运行命令时出现错误,而是我不确定如何配置它.

edit to anwer: Pascal T The issue is not so much that I'm getting an error when I try and run the command from the root pom, but that I'm not sure how to configure it.

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

for example the webapp1/pom.xml looks like:

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

更改为该目录并输入mvn jetty:run可以正常工作,并使我能够执行以下操作: http://localhost :8080/webapp1 .

changing to this directory and typing mvn jetty:run works just fine and affords me the ability to hit: http://localhost:8080/webapp1.

但是,我希望将其放置在webapp1的父目录中,并从父目录运行所有'n'个webapp.因此,具有 http://localhost:8080/webapp1

However, what I would like would be to be in the parent of webapp1, and run all 'n' webapps from the parent directory. Thus having http://localhost:8080/webapp1, and http://localhost:8080/webapp2 available with one command line parameter.

顺便说一句,如果答案涉及tomcat插件,那就没问题了.

btw, if the answer involved a tomcat plugin, that would be fine.

推荐答案

编辑:由于我对OP的期望有了更好的了解,因此我已经完全编辑了我的第一个答案.

EDIT: I've totally edited my first answer now that I have a better understanding of the OP's expectations.

签出 Cargo 一个薄包装器,它允许您以标准方式操作Java EE容器方式.

实际上,在货运网站上有一个教程使用Cargo Maven2插件自动启动/停止容器(可能在其启动时向其部署一些可部署项),这正是我所了解的.

Actually, there is a tutorial on Cargo's website that demonstrates how to use the Cargo Maven2 plugin to automatically start/stop a container (possibly deploying some deployables to it as it starts), which is what you're looking for from what I've understood.

我只是不确定从父目录执行此操作是否可行,是否有必要,或者是否可以从另一个目录执行此操作.我稍后再讲.首先让我们看一下Cargo Maven2插件的设置.

I'm just not sure that doing this from the parent directory is feasible and if it's a requirement or if it would be ok to do it from another directory. I'll come back on this later. Lets first take a look at the Cargo Maven2 plugin setup.

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

In your case, you can start with the minimal configuration (that uses Jetty 5.x which is Cargo's default container):

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

如果要使用Jetty 6.x,则必须在<container>元素中指定<containerId><type>:

If you want to use Jetty 6.x, you'll have to specify <containerId> and <type> in the <container> element:

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

然后,通过在插件配置内显式定义 deployables 添加要部署的模块(请参阅

Then, add the modules you want to deploy by defining deployables explicitly inside the plugin configuration (refer to the Maven2 Plugin Reference Guide for the details of the configuration) :

<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并通过简单的方法在其上部署Web应用程序(从包含cargo插件配置的项目中运行):

With this, you should be able to start Jetty and have your webapps deployed on it with a simple (to run from the project containing the cargo plugin configuration):

$ mvn cargo:start

我只是不确定这是否可以与父pom一起使用(我想知道这是否会导致循环依赖性问题),而我没有对其进行测试.但就我个人而言,我会将所有这些内容放入一个专用项目的pom中,例如在您的Web应用程序的同级项目中,而不是在父pom中.我认为这没什么大不了的,这是恕我直言,这是一个更好的设置,尤其是如果您打算将货物用于

I'm just not sure that this can work with the parent pom (I wonder if this can lead to cyclic dependencies issues) and I didn't test it. But personally, I'd put all this stuff in the pom of a dedicated project, e.g. in a sibling project of your webapps, and not in the parent pom. I don't think it's a really a big deal and this is IMHO a better setup, especially if you plan to use cargo for integration testing.

这篇关于如何从父Pom部署多个对等Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆