Jetty web application support library providing comprehensive webapp deployment, configuration, and class loading capabilities
—
Jetty WebApp uses a pluggable configuration system where different aspects of webapp deployment are handled by separate Configuration implementations. This system uses the ServiceLoader pattern with dependency resolution and lifecycle management.
The main interface that all configuration components implement.
/**
* Main interface for pluggable webapp configuration components.
* Configurations are discovered via ServiceLoader and manage specific
* aspects of webapp deployment and setup.
*/
public interface Configuration {
/**
* Attribute name for storing configuration list in webapp context
*/
String ATTR = "org.eclipse.jetty.webapp.configuration";
/**
* Pre-configure the webapp (early setup phase)
*/
void preConfigure(WebAppContext context) throws Exception;
/**
* Configure the webapp (main configuration phase)
*/
void configure(WebAppContext context) throws Exception;
/**
* Post-configure the webapp (finalization phase)
*/
void postConfigure(WebAppContext context) throws Exception;
/**
* De-configure the webapp (cleanup phase)
*/
void deconfigure(WebAppContext context) throws Exception;
/**
* Destroy configuration resources
*/
void destroy(WebAppContext context) throws Exception;
/**
* Check if this configuration is enabled by default
*/
boolean isEnabledByDefault();
/**
* Check if configuration should abort further processing
*/
boolean abort(WebAppContext context);
}Default implementations provided by the Configuration interface.
/**
* Check if configuration is available for use
*/
default boolean isAvailable() { return true; }
/**
* Get the configuration class this one replaces
*/
default Class<? extends Configuration> replaces() { return null; }
/**
* Get configuration class names this configuration depends on
*/
default Collection<String> getDependencies() { return Collections.emptyList(); }
/**
* Get configuration class names that depend on this configuration
*/
default Collection<String> getDependents() { return Collections.emptyList(); }
/**
* Get system classes matcher for this configuration
*/
default ClassMatcher getSystemClasses() { return null; }
/**
* Get server classes matcher for this configuration
*/
default ClassMatcher getServerClasses() { return null; }Base implementation providing common configuration functionality.
/**
* Abstract base class providing common configuration functionality
* including dependency management and class visibility controls.
*/
public abstract class AbstractConfiguration implements Configuration {
/**
* Create configuration enabled by default
*/
protected AbstractConfiguration();
/**
* Create configuration with specific enabled state
*/
protected AbstractConfiguration(boolean enabledByDefault);
/**
* Clone configuration from template to target webapp
*/
public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception;
}Methods available to Configuration implementations for common tasks.
/**
* Add dependency configuration class names
*/
protected void addDependencies(String... classes);
/**
* Add dependency configuration classes
*/
protected void addDependencies(Class<? extends Configuration>... classes);
/**
* Add dependent configuration class names
*/
protected void addDependents(String... classes);
/**
* Add dependent configuration classes
*/
protected void addDependents(Class<?>... classes);
/**
* Add system classes (loaded by system classloader)
*/
protected void protect(String... classes);
/**
* Add server classes (hidden from webapp)
*/
protected void hide(String... classes);
/**
* Expose server classes to webapp
*/
protected void expose(String... classes);
/**
* Both protect and expose classes
*/
protected void protectAndExpose(String... classes);Container class that manages an ordered list of Configuration instances.
/**
* Ordered list of Configuration instances with dependency resolution
* and lifecycle management.
*/
public class Configurations extends AbstractList<Configuration> implements Dumpable {
/**
* Create empty configurations list
*/
public Configurations();
/**
* Create configurations from class names
*/
public Configurations(String... classes);
/**
* Create configurations from class name list
*/
public Configurations(List<String> classes);
/**
* Copy constructor
*/
public Configurations(Configurations classlist);
}Static methods for managing known configurations and server defaults.
/**
* Get all known configuration implementations
*/
public static List<Configuration> getKnown();
/**
* Set known configuration class names
*/
public static void setKnown(String... classes);
/**
* Set server default configurations
*/
public static Configurations setServerDefault(Server server);
/**
* Get server default configurations
*/
public static Configurations getServerDefault(Server server);Methods for managing the configuration list.
/**
* Add configurations to the list
*/
public void add(Configuration... configurations);
/**
* Add configuration classes by name
*/
public void add(String... configClass);
/**
* Get configuration by type
*/
public <T> T get(Class<? extends T> configClass);
/**
* Get all configurations of a specific type
*/
public <T> List<T> getConfigurations(Class<? extends T> configClass);
/**
* Set configurations (replace all)
*/
public void set(Configuration... configurations);
public void set(String... configClass);
/**
* Remove configurations
*/
public void remove(Configuration... configurations);
public void remove(Class<? extends Configuration>... configClass);
public void remove(String... configClass);
/**
* Clear all configurations
*/
public void clear();
/**
* Get configuration list
*/
public List<Configuration> getConfigurations();
/**
* Convert to string array of class names
*/
public String[] toArray();
/**
* Get size of configuration list
*/
public int size();Methods for dependency resolution and executing configuration lifecycle.
/**
* Sort configurations based on dependencies
*/
public void sort();
/**
* Execute pre-configure phase for all configurations
*/
public void preConfigure(WebAppContext webapp) throws Exception;
/**
* Execute configure phase for all configurations
*/
public boolean configure(WebAppContext webapp) throws Exception;
/**
* Execute post-configure phase for all configurations
*/
public void postConfigure(WebAppContext webapp) throws Exception;Jetty WebApp includes numerous built-in Configuration implementations that are discovered via ServiceLoader:
/**
* Basic webapp configuration - sets up basic webapp structure and context
*/
public class WebAppConfiguration extends AbstractConfiguration {
public WebAppConfiguration();
}
/**
* Processes web.xml descriptor and applies servlet configuration
*/
public class WebXmlConfiguration extends AbstractConfiguration {
public WebXmlConfiguration();
}
/**
* Processes WEB-INF directory and sets up classpath from JARs and classes
*/
public class WebInfConfiguration extends AbstractConfiguration {
public WebInfConfiguration();
}
/**
* Processes META-INF directory and discovers web fragments
*/
public class MetaInfConfiguration extends AbstractConfiguration {
public MetaInfConfiguration();
}
/**
* Processes web fragments and handles ordering according to servlet spec
*/
public class FragmentConfiguration extends AbstractConfiguration {
public FragmentConfiguration();
}
/**
* Processes jetty-web.xml descriptor for Jetty-specific configuration
*/
public class JettyWebXmlConfiguration extends AbstractConfiguration {
public JettyWebXmlConfiguration();
}
/**
* Configures servlets and filters from annotations and descriptors
*/
public class ServletsConfiguration extends AbstractConfiguration {
public ServletsConfiguration();
}/**
* Configures JNDI context and resources
*/
public class JndiConfiguration extends AbstractConfiguration {
public JndiConfiguration();
}
/**
* Configures JAAS authentication and security realms
*/
public class JaasConfiguration extends AbstractConfiguration {
public JaasConfiguration();
}
/**
* Configures JASPI (Java Authentication Service Provider Interface) authentication
*/
public class JaspiConfiguration extends AbstractConfiguration {
public JaspiConfiguration();
}
/**
* Configures JMX management and monitoring capabilities
*/
public class JmxConfiguration extends AbstractConfiguration {
public JmxConfiguration();
}
/**
* Configures JSP compilation and runtime support
*/
public class JspConfiguration extends AbstractConfiguration {
public JspConfiguration();
}Each configuration declares dependencies that control execution order:
// Example dependency relationships
WebInfConfiguration -> depends on nothing (runs first)
WebXmlConfiguration -> depends on WebInfConfiguration
MetaInfConfiguration -> depends on WebInfConfiguration
FragmentConfiguration -> depends on WebXmlConfiguration, MetaInfConfiguration
ServletsConfiguration -> depends on FragmentConfiguration
JettyWebXmlConfiguration -> depends on FragmentConfigurationSystem for wrapping and decorating configurations.
/**
* Functional interface for wrapping configurations
*/
public interface WrapperFunction {
Configuration wrapConfiguration(Configuration configuration);
}
/**
* Wrapper implementation for Configuration delegation
*/
public static class Wrapper implements Configuration {
/**
* Create wrapper with delegate configuration
*/
public Wrapper(Configuration delegate);
/**
* Get the wrapped configuration
*/
public Configuration getWrapped();
// All Configuration methods are delegated to wrapped instance
}// Use default configurations
WebAppContext webapp = new WebAppContext();
// Default configurations are automatically applied
// Or set specific configurations
webapp.setConfigurationClasses(new String[] {
"org.eclipse.jetty.webapp.WebInfConfiguration",
"org.eclipse.jetty.webapp.WebXmlConfiguration",
"org.eclipse.jetty.webapp.MetaInfConfiguration",
"org.eclipse.jetty.webapp.FragmentConfiguration"
});public class MyCustomConfiguration extends AbstractConfiguration {
public MyCustomConfiguration() {
super();
// Add dependencies
addDependencies(WebInfConfiguration.class, WebXmlConfiguration.class);
// Hide internal classes
hide("com.mycompany.internal.");
}
@Override
public void configure(WebAppContext context) throws Exception {
// Custom configuration logic
ServletHolder servlet = new ServletHolder(new MyServlet());
context.getServletHandler().addServlet(servlet);
}
}
// Add to webapp
webapp.addConfiguration(new MyCustomConfiguration());// Set server-wide default configurations
Server server = new Server();
Configurations.setServerDefault(server);
// All webapps on this server will use these defaults
// Individual webapps can still override// Configurations are automatically sorted by dependencies
Configurations configs = new Configurations(
"org.eclipse.jetty.webapp.WebXmlConfiguration",
"org.eclipse.jetty.webapp.WebInfConfiguration", // Depends on WebXml
"org.eclipse.jetty.webapp.MetaInfConfiguration"
);
// Sort resolves dependencies
configs.sort();
// Execute lifecycle phases
configs.preConfigure(webapp);
configs.configure(webapp);
configs.postConfigure(webapp);// Wrap configuration to add behavior
Configuration.WrapperFunction wrapper = config -> {
return new Configuration.Wrapper(config) {
@Override
public void configure(WebAppContext context) throws Exception {
System.out.println("Before: " + getWrapped().getClass().getSimpleName());
super.configure(context);
System.out.println("After: " + getWrapped().getClass().getSimpleName());
}
};
};
// Apply wrapper to configurations
Configurations configs = webapp.getConfigurations();
for (int i = 0; i < configs.size(); i++) {
configs.set(i, wrapper.wrapConfiguration(configs.get(i)));
}Install with Tessl CLI
npx tessl i tessl/maven-org-eclipse-jetty--jetty-webapp