tags:

views:

1159

answers:

2

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.

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

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?

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.

for example the webapp1/pom.xml looks like:

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

changing to this directory and typing mvn jetty:run works just fine and affords me the ability to hit: 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.

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

+5  A: 

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

Check out Cargo, a thin wrapper that allows you to manipulate Java EE containers in a standard way.

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.

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.

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

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

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>

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

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.

Pascal Thivent
+1, but consider one addition: if the configuration in the parent is set in the pluginManagement section, the child webapps need only declare the plugin (as in the OPs code snippet) for the configuration to be inherited. This avoids any cycle issues.
Rich Seller
A: 

Maybe this link solves your problem:

http://www.jiajia.eu/post/2008/10/08/Deploy-multiple-web-apps-with-maven-jetty-plugin.aspx.

the link above is broken, so here is a new one:

http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin

See section "Running Multiple Webapps".

Janning
+1 This solution uses maven jetty plug-in to deploy the "sister" web application linked as relative path (../webapp2/target/webapp2.war) via jetty.xml, while still retaining fast development cycle with hot-deploy-ability for the webapp1.
Palimondo
this link does not work.
Nathan Feger
The original link target is no longer available. I added a new link.
Janning