Search code examples
mavenjettymaven-jetty-plugin

How does maven jetty package a war?


I am running an open source piece of software (https://github.com/att/XACML) and the documentation says to use maven jetty to run the application. This works fine.

However, I am trying to run it without maven as a dependency, so I am thinking of using the generated war and deploying it with jetty. However, this approach gives me errors specific to the war (can not instantiate null etc.) that do not sure up when running maven jetty.

So my question is: how does maven jetty package the war? Is there anything it does at runtime that would make it different than just trying to deploy the war on its own? What is the difference between using maven jetty and using something like jetty runner with the war generated from maven clean install?


Solution

  • Jetty does not package a war.

    Maven does, and you need ...

    1. Your project's pom.xml should be declared as <packaging>war</packaging>
    2. You have a src/main/webapp directory.
    3. You have maven execute the package phase.

    When you use something like mvn jetty:run-war the first thing that happens is the package phase executes, THEN the jetty:run-war goal executes.

    See: JettyRunWarMojo.java

    @Mojo(name = "run-war", 
          requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
    @Execute(phase = LifecyclePhase.PACKAGE)
    public class JettyRunWarMojo extends AbstractMojo
    

    Jetty is not doing the packaging of war, Maven and it's default package phase is (and the behaviors here are determined by the standard maven lifecycle defined by your <packaging>war</packaging>)

    See: https://maven.apache.org/ref/3.2.2/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging