I am launching an embedded Jetty instance containing a single webapp. The webapp launches on start-up. I'd like to know how to detect if the Webapp's contextInitialized throws an exception.
When the webapp throws an exception, Server.start() doesn't and server.isRunning() returns true. Is there a way for me to listen for webapp exceptions from outside the container?
Answering my own question.
Setting WebAppContext.setThrowUnavailableOnStartupException(true)
causes the server to propagate any webapp exceptions to Server.start()
. I'm guessing one could also invoke WebAppContext.isFailed()
after server start-up to check individual contexts.
I stumbled across this trying to make this work for a non-embedded solution. In case anyone is in a similar boat, the solution for that case is to create WEB-INF/jetty-env.xml
with the following contents:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="throwUnavailableOnStartupException">true</Set>
</Configure>
The server will fail startup on an exception as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With