We're using Jetty 9.3 with a single application in ROOT.war
with a web-xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<listener>
<listener-class>path.AppEventListener</listener-class>
</listener>
<servlet>
<servlet-name>MyService</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- ***NOTE*** added next line per minus's answer -->
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>path.MyService</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
If the MyService
application fails to initialize correctly on startup, we would like Jetty to shut down immediately, but we can't seem to figure out how to do so. This question sounds like it might be relevant, but doesn't seem to make any change in our hands, possibly because we use ant
without ivy
as the build tool.
The (undesired) behavior we currently see is that Jetty doesn't attempt to initialize the application until it's needed, and then throws an exception.
Update based on minus's answer:
Note I updated the web.xml
above per said answer.
I added a jetty-env.xml
file to WEB-INF as described in this question:
$ jar tf webapps/ROOT.war | grep -v lib | grep -v class
META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/web.xml
WEB-INF/jetty-env.xml
$ jar xf webapps/ROOT.war WEB-INF/jetty-env.xml
$ cat WEB-INF/jetty-env.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="throwUnavailableOnStartupException">true</Set>
</Configure>
Note I also updated the DOCTYPE line for Jetty 9.3.
At this point the application starts up immediately and throws an error, but Jetty stays up. I see the following in the logs:
2017-03-13 18:36:59.597:WARN:ROOT:main: unavailable
2017-03-13 18:36:59.599:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@6767c1fc{/,file:///tmp/jetty-0.0.0.0-20002-ROOT.war-_-any-593353947747896998.dir/webapp/,UNAVAILABLE}{/ROOT.war}