CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-eclipse-jetty-ee10--jetty-ee10-webapp

Jetty web application support for Jakarta EE 10 with full servlet specification compliance

Pending
Overview
Eval results
Files

webapp-context.mddocs/

Web Application Context

The WebAppContext is the main entry point for deploying and managing web applications in Jetty EE10. It extends ServletContextHandler and coordinates the construction and configuration of nested handlers including security, session, and servlet handlers.

Core WebAppContext Class

public class WebAppContext extends ServletContextHandler 
    implements WebAppClassLoader.Context, Deployable {
    
    // Constructors
    public WebAppContext();
    public WebAppContext(String webApp, String contextPath);
    public WebAppContext(Resource webApp, String contextPath);
    public WebAppContext(SessionHandler sessionHandler, 
        SecurityHandler securityHandler, ServletHandler servletHandler, 
        ErrorHandler errorHandler);
    
    // Static methods
    public static WebAppContext getCurrentWebAppContext();
    
    // Configuration methods
    public void initializeDefaults(Map<String, String> properties);
    public boolean configure() throws Exception;
    public void preConfigure() throws Exception;
    public void postConfigure() throws Exception;
    
    // Context path management
    public boolean isContextPathDefault();
    public void setContextPath(String contextPath);
    public void setDefaultContextPath(String contextPath);
    
    // WAR and resource management
    public String getWar();
    public void setWar(String war);
    public void setWarResource(Resource war);
    public Resource getResource(String pathInContext) throws MalformedURLException;
    public Resource getWebInf() throws IOException;
    
    // Resource aliases
    public void setResourceAlias(String alias, String uri);
    public Map<String, String> getResourceAliases();
    public String getResourceAlias(String path);
    
    // ClassLoader management
    public void setClassLoader(ClassLoader classLoader);
    public ResourceFactory getResourceFactory();
    
    // Configuration discovery and management
    public boolean isConfigurationDiscovered();
    public void setConfigurationDiscovered(boolean discovered);
    public String[] getConfigurationClasses();
    public Configurations getConfigurations();
    
    // Descriptor management
    public String getDefaultsDescriptor();
    public String getOverrideDescriptor();
    public List<String> getOverrideDescriptors();
    
    // Security and permissions
    public PermissionCollection getPermissions();
    
    // Class visibility controls
    public void setHiddenClassMatcher(ClassMatcher hiddenClasses);
    public void setProtectedClassMatcher(ClassMatcher protectedClasses);
    public ClassMatcher getProtectedClassMatcher();
    public ClassMatcher getHiddenClassMatcher();
    public String[] getProtectedClasses();
    public String[] getHiddenClasses();
    public boolean isHiddenClass(Class<?> clazz);
    public boolean isProtectedClass(Class<?> clazz);
    
    // Deployment options
    public boolean isDistributable();
    public boolean isExtractWAR();
    public boolean isCopyWebDir();
    public boolean isCopyWebInf();
    public boolean isParentLoaderPriority();
    
    // Classpath extensions
    public List<Resource> getExtraClasspath();
    public void setExtraClasspath(String extraClasspath);
    public void setExtraClasspath(List<Resource> extraClasspath);
    
    // Metadata access
    public MetaData getMetaData();
    
    // Exception handling
    public Throwable getUnavailableException();
    
    // Display name
    public void setDisplayName(String servletContextName);
}

Usage Examples

Basic Web Application Setup

import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.server.Server;

// Create and configure a web application
WebAppContext webapp = new WebAppContext();
webapp.setWar("/path/to/myapp.war");
webapp.setContextPath("/myapp");

// Optional: Set resource aliases
webapp.setResourceAlias("/docs", "/usr/share/doc/myapp");

// Add to server
Server server = new Server(8080);
server.setHandler(webapp);
server.start();

Directory-Based Web Application

import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.util.resource.ResourceFactory;

// Deploy from directory instead of WAR
WebAppContext webapp = new WebAppContext();
webapp.setWarResource(ResourceFactory.of(webapp).newResource("/path/to/webapp/dir"));
webapp.setContextPath("/myapp");

// Configure extraction options
webapp.setExtractWAR(false); // Don't extract since it's already a directory
webapp.setCopyWebDir(false);

Custom ClassLoader Configuration

import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.util.ClassMatcher;

WebAppContext webapp = new WebAppContext();
webapp.setWar("/path/to/webapp.war");
webapp.setContextPath("/myapp");

// Configure class visibility
ClassMatcher protectedClasses = new ClassMatcher();
protectedClasses.add("org.eclipse.jetty.");
protectedClasses.add("java.lang.");
webapp.setProtectedClassMatcher(protectedClasses);

ClassMatcher hiddenClasses = new ClassMatcher();
hiddenClasses.add("org.eclipse.jetty.util.log.");
webapp.setHiddenClassMatcher(hiddenClasses);

// Add extra classpath entries
webapp.setExtraClasspath("/path/to/extra/classes:/path/to/lib/custom.jar");

Configuration Management

import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.ee10.webapp.Configurations;
import org.eclipse.jetty.ee10.webapp.WebXmlConfiguration;
import org.eclipse.jetty.ee10.webapp.MetaInfConfiguration;

WebAppContext webapp = new WebAppContext();
webapp.setWar("/path/to/webapp.war");
webapp.setContextPath("/myapp");

// Custom configuration set
Configurations configs = new Configurations();
configs.add(new WebXmlConfiguration());
configs.add(new MetaInfConfiguration());
webapp.setConfigurations(configs);

// Alternative: Use default configurations
webapp.setConfigurationDiscovered(true);

Programmatic Deployment Lifecycle

import org.eclipse.jetty.ee10.webapp.WebAppContext;

WebAppContext webapp = new WebAppContext("/path/to/webapp.war", "/myapp");

try {
    // Manual lifecycle management
    webapp.preConfigure();
    boolean success = webapp.configure();
    if (success) {
        webapp.postConfigure();
        // Web application is now ready
    }
} catch (Exception e) {
    // Handle configuration errors
    System.err.println("Failed to configure webapp: " + e.getMessage());
}

Resource and Descriptor Override

import org.eclipse.jetty.ee10.webapp.WebAppContext;

WebAppContext webapp = new WebAppContext();
webapp.setWar("/path/to/webapp.war");
webapp.setContextPath("/myapp");

// Override default descriptors
webapp.setDefaultsDescriptor("/path/to/custom-webdefault.xml");
webapp.setOverrideDescriptor("/path/to/override.xml");

// Multiple override descriptors
List<String> overrides = Arrays.asList(
    "/path/to/override1.xml",
    "/path/to/override2.xml"
);
webapp.setOverrideDescriptors(overrides);

WebAppContext.Context Interface

The WebAppContext implements the Context interface that provides services to the WebAppClassLoader:

public interface Context {
    Resource newResource(String urlOrPath) throws IOException;
    PermissionCollection getPermissions();
    boolean isParentLoaderPriority();
    List<Resource> getExtraClasspath();
    boolean isHiddenResource(String name, URL parentUrl);
    boolean isProtectedResource(String name, URL webappUrl);
}

Key Constants

public static final String WEB_DEFAULTS_XML = 
    "org/eclipse/jetty/ee10/webapp/webdefault-ee10.xml";

// Deprecated constants (use WebAppClassLoading equivalents)
@Deprecated
public static final String SERVER_SYS_CLASSES = 
    WebAppClassLoading.PROTECTED_CLASSES_ATTRIBUTE;
@Deprecated  
public static final String SERVER_SRV_CLASSES = 
    WebAppClassLoading.HIDDEN_CLASSES_ATTRIBUTE;

Error Handling

WebAppContext methods can throw various exceptions during configuration and deployment:

  • Exception - General configuration errors during configure(), preConfigure(), postConfigure()
  • MalformedURLException - Invalid URL when accessing resources via getResource()
  • IOException - I/O errors when accessing WAR files or directories

Common error scenarios:

  • Invalid WAR file path or corrupted WAR
  • Missing required configuration files
  • ClassLoader conflicts with protected/hidden class patterns
  • Insufficient permissions for resource access
  • Circular dependencies in configuration chain

Install with Tessl CLI

npx tessl i tessl/maven-org-eclipse-jetty-ee10--jetty-ee10-webapp

docs

classloader.md

configuration.md

index.md

metadata.md

webapp-context.md

tile.json