Embedded Apache Tomcat servlet container with Jakarta Servlet API, HTTP connectors, and lifecycle management for Java web applications
Resource management system for serving static content, loading classes, accessing JAR files, and managing web application resources. Supports multiple resource sets, caching, virtual directories, overlays, and efficient resource lookup.
Root resource management interface for a web application.
public interface WebResourceRoot extends Lifecycle {
// Resource lookup
WebResource getResource(String path);
WebResource getClassLoaderResource(String path);
WebResource[] getResources(String path);
WebResource[] getClassLoaderResources(String path);
WebResource[] listResources(String path);
// Resource sets
void addPreResources(WebResourceSet webResourceSet);
WebResourceSet[] getPreResources();
void addJarResources(WebResourceSet webResourceSet);
WebResourceSet[] getJarResources();
void addPostResources(WebResourceSet webResourceSet);
WebResourceSet[] getPostResources();
void createWebResourceSet(ResourceSetType type, String webAppMount, String base,
String archivePath, String internalPath);
void createWebResourceSet(ResourceSetType type, String webAppMount, URL url, String internalPath);
// Context
Context getContext();
void setContext(Context context);
// Caching
void setCachingAllowed(boolean cachingAllowed);
boolean isCachingAllowed();
void setCacheTtl(long ttl);
long getCacheTtl();
void setCacheMaxSize(long cacheMaxSize);
long getCacheMaxSize();
void setCacheObjectMaxSize(int cacheObjectMaxSize);
int getCacheObjectMaxSize();
// Archive indexing
void setArchiveIndexStrategy(String archiveIndexStrategy);
String getArchiveIndexStrategy();
// JAR scanning
void registerTrackedResource(TrackedWebResource trackedResource);
void deregisterTrackedResource(TrackedWebResource trackedResource);
// Directory operations
boolean mkdir(String path);
boolean write(String path, InputStream is, boolean overwrite);
// Resource listing
void backgroundProcess();
// Additional resource methods
String[] list(String path);
Set<String> listWebAppPaths(String path);
// Symbolic link configuration
void setAllowLinking(boolean allowLinking);
boolean getAllowLinking();
// File tracking
void setTrackLockedFiles(boolean trackLockedFiles);
boolean getTrackLockedFiles();
// Archive index strategy
ArchiveIndexStrategy getArchiveIndexStrategyEnum();
// Base URLs
List<URL> getBaseUrls();
// Cache management
void gc();
default CacheStrategy getCacheStrategy();
default void setCacheStrategy(CacheStrategy strategy);
// Read-only mode
default void setReadOnly(boolean readOnly);
default boolean isReadOnly();
}Type of web resource set for specifying resource ordering.
public enum ResourceSetType {
PRE, // Pre-resources (highest priority)
RESOURCE_JAR, // Resource JARs
POST, // Post-resources
CLASSES_JAR; // Classes JARs (lowest priority)
}Represents a file or directory within a web application.
public interface WebResource {
// Timing
long getLastModified();
String getLastModifiedHttp();
long getCreation();
// Existence
boolean exists();
boolean isVirtual();
boolean isDirectory();
boolean isFile();
// Operations
boolean delete();
// Identity
String getName();
long getContentLength();
String getCanonicalPath();
String getWebappPath();
String getETag();
URL getURL();
CodeSource getCodeBase();
// Content
boolean canRead();
byte[] getContent();
InputStream getInputStream();
// Certificates
Certificate[] getCertificates();
Manifest getManifest();
// MIME type
void setMimeType(String mimeType);
String getMimeType();
// Resource root
WebResourceRoot getWebResourceRoot();
}Set of resources from a specific location.
public interface WebResourceSet extends Lifecycle {
// Resource root
void setRoot(WebResourceRoot root);
// Resource lookup
WebResource getResource(String path);
String[] list(String path);
Set<String> listWebAppPaths(String path);
// Directory operations
boolean mkdir(String path);
boolean write(String path, InputStream is, boolean overwrite);
// Configuration
void setReadOnly(boolean readOnly);
boolean isReadOnly();
// Classloader resource
boolean getClassLoaderOnly();
void setClassLoaderOnly(boolean classLoaderOnly);
boolean getStaticOnly();
void setStaticOnly(boolean staticOnly);
// JAR/Archive handling
URL getBaseUrl();
}import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.Context;
import org.apache.catalina.WebResourceRoot;
import org.apache.catalina.webresources.StandardRoot;
public class ResourceCachingExample {
public static void main(String[] args) throws Exception {
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
Context ctx = tomcat.addWebapp("/", "/path/to/webapp");
// Configure resource caching
StandardRoot resources = new StandardRoot(ctx);
resources.setCachingAllowed(true);
resources.setCacheTtl(5000); // 5 seconds
resources.setCacheMaxSize(10240); // 10MB
resources.setCacheObjectMaxSize(512); // 512KB
ctx.setResources(resources);
tomcat.start();
tomcat.getServer().await();
}
}Install with Tessl CLI
npx tessl i tessl/maven-org-apache-tomcat-embed--tomcat-embed-core