Jetty Rewrite for UberJar

Hi colleagues,

In my project, I need to configure redirection rules using jetty-rewrite in the jetty.xml configuration file. The project is built as an uberJar, but for some reason, the added jetty-rewrite dependency is not being picked up during runtime (even though jetty-rewrite is present in the project dependencies). As a result, I get the following error:

12:22:42.578 WARN  o.eclipse.jetty.xml.XmlConfiguration    - Config error at <Call name="addRule">
    <Arg>
        <New class="org.eclipse.jetty.rewrite.handler.RedirectPatternRule">
            <Set name="pattern" type="String"/>
            <Set name="location">/am/</Set>
        </New>
    </Arg>
</Call>
java.lang.ClassNotFoundException: org.eclipse.jetty.rewrite.handler.RedirectPatternRule
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at org.eclipse.jetty.util.Loader.loadClass(Loader.java:64)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:1006)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1540)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:1441)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.access$700(XmlConfiguration.java:395)
    ...

Most likely, the dependency is not included in the final uberJar.

Could you please advise how to correctly integrate jetty-rewrite into an uberJar build?
Important: I cannot use the WAR option; I specifically need an uberJar.

Hi,
Which type of dependency do you use for the library?
You should use server() dependency type, added in this ticket: Dependencies of uberJar type must be declared only on top level · Issue #126 · cuba-platform/cuba-gradle-plugin · GitHub

1 Like