Search code examples
maven-jetty-plugin

java.lang.ClassCastException: org.eclipse.jetty.webapp.WebAppContext cannot be cast to org.eclipse.jetty.maven.plugin.JettyWebAppContext


ON jetty 8 to jetty 9 migration when using jetty-maven-plugin, the application cannot load because of the class cast exception:

java.lang.ClassCastException: org.eclipse.jetty.webapp.WebAppContext cannot be cast to org.eclipse.jetty.maven.plugin.JettyWebAppContext


Solution

  • Change the context handler from WebAppContext to JettyWebApp context.

    <contextHandlers>
                            <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                                <war>../../flieName.war</war>
                                <contextPath>/yourPath</contextPath>
                            </contextHandler>
                            <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                                <war>../../yourWar.war</war>
                                <contextPath>/anotherPath</contextPath>
                            </contextHandler>
                            <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                                <war>../../../anotherApp.war</war>
                                <contextPath>/oneMorePath</contextPath>
                            </contextHandler>
    

    Also make the same change to your jetty-context.xml

    <Configure class="org.eclipse.jetty.maven.plugin.JettyWebAppContext">