Skip to content

Commit

Permalink
Merge pull request #660 from nscuro/jetty-customization
Browse files Browse the repository at this point in the history
Allow for customization of the Jetty WebAppContext
  • Loading branch information
nscuro authored Sep 9, 2024
2 parents b1ca4f3 + 1e77df8 commit 245165a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.URLResourceFactory;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.slf4j.Logger;
import org.slf4j.bridge.SLF4JBridgeHandler;

Expand Down Expand Up @@ -93,6 +96,19 @@ public static void main(final String[] args) throws Exception {
final URL location = protectionDomain.getCodeSource().getLocation();
context.setWar(location.toExternalForm());

// Allow applications to customize the WebAppContext via Jetty context XML file.
// An example use-case is the customization of JARs that Jetty shall scan for annotations.
//
// https://jetty.org/docs/jetty/12/operations-guide/xml/index.html
// https://jetty.org/docs/jetty/12/operations-guide/annotations/index.html
final URL jettyContextUrl = Thread.currentThread().getContextClassLoader().getResource("WEB-INF/jetty-context.xml");
if (jettyContextUrl != null) {
LOGGER.debug("Applying Jetty customization from {}", jettyContextUrl);
final Resource jettyContextResource = new URLResourceFactory().newResource(jettyContextUrl);
final var xmlConfiguration = new XmlConfiguration(jettyContextResource);
xmlConfiguration.configure(context);
}

server.setHandler(context);
server.addBean(new ErrorHandler());
try {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<plugin.cyclonedx.outputReactorProjects>true</plugin.cyclonedx.outputReactorProjects>

<!-- Dependency Versions -->
<lib.alpine.executable.war.version>3.0.2-SNAPSHOT</lib.alpine.executable.war.version>
<lib.alpine.executable.war.version>3.1.0-SNAPSHOT</lib.alpine.executable.war.version>
<lib.angus-mail.version>2.0.3</lib.angus-mail.version>
<lib.bcrypt.version>0.4</lib.bcrypt.version>
<lib.caffeine.version>3.1.8</lib.caffeine.version>
Expand Down

0 comments on commit 245165a

Please # to comment.