Jetty: Detect if Webapp failed to start

梦想的初衷 提交于 2019-12-07 01:38:29

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/8645792/jetty-detect-if-webapp-failed-to-start

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!