Speeding up Slow Jetty 8 Startups
A few weeks ago our Jetty startup time went from 8 seconds to over 60. We discovered it was searching every class in every jar in WEB-INF/lib and WEB-INF/classes for the JEE annotations, e.g. annotations such as @WebFilter which replace fragments inside the web.xml file. This is normal behavior, according to many sources, and no fault of Jetty’s. However, a quick search for javax.servlet.annotation showed that we were not using any of these. Adding ‘metadata-complete=”true”‘ to our web.xml’s web-app restored our startup time to 8 seconds.
<?xml version="1.0" encoding="UTF-8"?> <web-app 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" metadata-complete="true" version="3.0">
This attribute tells the container that the web.xml contains the complete configuration. I think this is a fairly well-known topic, but worth (re)posting if it saves someone else some time.