views:

132

answers:

2

I'm trying to split a Maven WAR project into two modules, so that I can build a separate JAR file with command line tools. The result has the following structure:

  • pom.xml (packaging pom, has two modules)
  • project-jar/
    • pom.xml (packaging jar)
  • project-war/
    • pom.xml (packaging war, depends on project-jar)

If I run mvn commands from the root, everything works fine. I'd like to keep using mvn jetty:run, but for that I need to execute the command in the WAR subproject. If I do that, fails to find the project-jar subproject, so it won't run. Even mvn jetty:run-war with a completely assembled WAR file in the target directory fails, because it first tries to "build" the project. I've only managed to make it work by installing project-jar into the local Maven repository, which isn't very nice.

Is there a way to use the Jetty plugin in a multi-module Maven configuration?

+2  A: 

There is no magical solution and the only one I know is a bit hacky and rely on the extraClasspath element that you can use to declare extra class directories, relatively. Like this (from JETTY-662):

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>7.0.1.v20091125</version>
  <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <webAppConfig>
      <contextPath>/my-context</contextPath>
      <extraClasspath>target/classes;../my-jar-dependency/target/classes</extraClasspath>
    </webAppConfig>
    <scanTargets>
      <scanTarget>../my-jar-dependency/target/classes</scanTarget>
    </scanTargets>
  </configuration>
</plugin>
Pascal Thivent
Hm, this doesn't actually help me, because it fails with a BUILD error "Failed to resolve artifact." (the sibling JAR project) before the Jetty plugin even gets executed. So it seems I need a general solution for Maven in the first place. :(
Lukáš Lalinský
@Lukáš Maven uses the local repository to resolve dependencies so they **must** be installed (i.e. you need to `install` all modules first by running a reactor build on the parent at least once). Then the above will work, even if the installed JARs are "outdated".
Pascal Thivent
Ah, I was hoping to avoid that. One alternative I found out was setting the jetty plugin on the parent and pointing it to the right war file (and then use jetty:run-war), but I'll probably need to run install anyway to make NetBeans happy.
Lukáš Lalinský
+1  A: 

Using extraClasspath in jetty configuration works... but for some reason, if dependant jars (from other modules) are outdated some things won't work correctly.

jaime