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
(packagingpom
, has two modules)project-jar/
pom.xml
(packagingjar
)
project-war/
pom.xml
(packagingwar
, depends onproject-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?
Best Answer
Create a profile inside the war module (
project-war
). Within this profile, configure jetty to attach to a lifecycle phase and execute therun
goal explicitly. Now when maven runs from the toplevel project with that profile enabled, it will invoke jetty:run and have sister module dependency resolution (as is normal when executing maven commands from the toplevel project).The example configuration, when placed in the pom.xml of the web module (
project-war
), arranges for jetty:run to execute during thetest
phase. (You may choose another phase, but make sure it's aftercompile
.)Run from toplevel:
mvn test -Pjetty-run
ormvn test -DskipTests=true -Pjetty-run
. This will compile dependencies as required and make them available but invoke jetty:run within the correct module.