Jetty deployers - Webapp Deploy Management component
—
Provider system for discovering and deploying applications from various sources like directories, WAR files, and XML descriptors. Providers implement pluggable discovery mechanisms that automatically detect deployable applications and create App instances for the DeploymentManager.
Base interface for objects responsible for providing Apps to the DeploymentManager. Providers discover applications from various sources and create appropriate context handlers.
/**
* Interface for objects responsible for providing Apps to the DeploymentManager
*/
public interface AppProvider extends LifeCycle {
/** Sets the deployment manager that will receive discovered apps */
void setDeploymentManager(DeploymentManager deploymentManager);
/** Creates a context handler for the specified app */
ContextHandler createContextHandler(App app) throws Exception;
/** Returns the environment name this provider is designed for */
String getEnvironmentName();
}Abstract base provider for loading webapps by scanning directories. Provides file system monitoring, change detection, and automatic deployment/redeployment capabilities.
/**
* Abstract base provider for loading webapps by scanning directories
*/
public abstract class ScanningAppProvider extends ContainerLifeCycle implements AppProvider {
/** Creates a new scanning provider with default settings */
public ScanningAppProvider();
/** Creates a new scanning provider with a custom filename filter */
public ScanningAppProvider(FilenameFilter filter);
/** Returns the environment name this provider targets */
public String getEnvironmentName();
/** Sets the environment name this provider is for */
public void setEnvironmentName(String environmentName);
/** Returns if real paths should be used instead of symbolic links */
public boolean isUseRealPaths();
/** Sets whether to use real paths instead of following symbolic links */
public void setUseRealPaths(boolean useRealPaths);
/** Returns the deployment manager */
public DeploymentManager getDeploymentManager();
/** Sets the deployment manager that will receive discovered apps */
public void setDeploymentManager(DeploymentManager deploymentManager);
/** Returns the monitored directory as a Resource */
public Resource getMonitoredDirResource();
/** Returns the monitored directory name */
public String getMonitoredDirName();
/** Sets a single monitored directory resource */
public void setMonitoredDirResource(Resource resource);
/** Sets the monitored directory by name */
public void setMonitoredDirName(String dir);
/** Sets multiple monitored directories */
public void setMonitoredDirectories(Collection<String> directories);
/** Sets monitored resources directly */
public void setMonitoredResources(List<Resource> resources);
/** Returns all monitored resources */
public List<Resource> getMonitoredResources();
/** Returns the scan interval in seconds */
public int getScanInterval();
/** Sets the scan interval in seconds (0 disables scanning) */
public void setScanInterval(int scanInterval);
/** Returns if the initial scan is deferred until after startup */
public boolean isDeferInitialScan();
/** Sets whether to defer the initial scan until after startup */
public void setDeferInitialScan(boolean defer);
/** Adds a scanner listener for custom file change handling */
public void addScannerListener(Scanner.Listener listener);
/** Triggers a manual scan of monitored directories */
public void scan();
/** Returns string representation of the provider */
public String toString();
// Protected methods for extension
/** Returns index of currently deployed applications */
protected Map<Path, App> getDeployedApps();
/** Creates a new App object for the specified path */
protected App createApp(Path path);
/** Called when a new deployable path is discovered */
protected void pathAdded(Path path) throws Exception;
/** Called when a deployable path changes */
protected void pathChanged(Path path) throws Exception;
/** Called when a deployable path is removed */
protected void pathRemoved(Path path) throws Exception;
}Usage Examples:
import org.eclipse.jetty.deploy.providers.ScanningAppProvider;
import org.eclipse.jetty.util.Scanner;
// Custom provider extending ScanningAppProvider
public class CustomProvider extends ScanningAppProvider {
public CustomProvider() {
super();
setEnvironmentName("ee10");
}
@Override
public ContextHandler createContextHandler(App app) throws Exception {
// Custom context handler creation logic
ContextHandler handler = new ContextHandler();
handler.setContextPath(app.getContextPath());
return handler;
}
}
// Configure scanning provider
CustomProvider provider = new CustomProvider();
provider.setMonitoredDirName("/opt/webapps");
provider.setScanInterval(30); // Scan every 30 seconds
provider.setDeferInitialScan(false);
provider.setUseRealPaths(true);
// Add custom scanner listener
provider.addScannerListener(new Scanner.Listener() {
@Override
public void fileAdded(String filename) throws Exception {
System.out.println("New app detected: " + filename);
}
@Override
public void fileRemoved(String filename) throws Exception {
System.out.println("App removed: " + filename);
}
});
deploymentManager.addAppProvider(provider);Concrete provider for scanning webapps directories for contexts to deploy including WAR files, directories, and XML descriptors. Provides comprehensive webapp deployment with extensive configuration options.
/**
* Provider for scanning webapps directories for contexts to deploy
* (WAR files, directories, XML descriptors)
*/
public class ContextProvider extends ScanningAppProvider {
/** Creates a new context provider with default settings */
public ContextProvider();
/** Returns provider-specific properties */
public Map<String, String> getProperties();
/** Loads properties from a resource */
public void loadProperties(Resource resource) throws IOException;
/** Loads properties from a file path */
public void loadPropertiesFromPath(Path path) throws IOException;
/** Loads properties from a string path */
public void loadPropertiesFromString(String path) throws IOException;
/** Returns whether WAR files should be extracted */
public boolean isExtractWars();
/** Sets whether WAR files should be extracted during deployment */
public void setExtractWars(boolean extractWars);
/** Returns parent classloader priority setting */
public boolean isParentLoaderPriority();
/** Sets parent classloader priority for web applications */
public void setParentLoaderPriority(boolean parentLoaderPriority);
/** Returns the defaults descriptor path */
public String getDefaultsDescriptor();
/** Sets the defaults descriptor for web applications */
public void setDefaultsDescriptor(String defaultsDescriptor);
/** Sets configuration classes as comma-separated string */
public void setConfigurationClasses(String configurations);
/** Sets configuration classes array */
public void setConfigurationClasses(String[] configurations);
/** Returns the configuration classes */
public String[] getConfigurationClasses();
/** Creates a context handler for the specified app */
public ContextHandler createContextHandler(App app) throws Exception;
}Usage Examples:
import org.eclipse.jetty.deploy.providers.ContextProvider;
// Basic context provider setup
ContextProvider contextProvider = new ContextProvider();
contextProvider.setMonitoredDirName("webapps");
contextProvider.setScanInterval(10);
// Configure webapp deployment options
contextProvider.setExtractWars(true);
contextProvider.setParentLoaderPriority(false);
contextProvider.setDefaultsDescriptor("etc/webdefault.xml");
// Set configuration classes for specific webapp features
contextProvider.setConfigurationClasses(new String[] {
"org.eclipse.jetty.ee10.webapp.WebInfConfiguration",
"org.eclipse.jetty.ee10.webapp.WebXmlConfiguration",
"org.eclipse.jetty.ee10.webapp.MetaInfConfiguration",
"org.eclipse.jetty.ee10.webapp.FragmentConfiguration",
"org.eclipse.jetty.ee10.webapp.JettyWebXmlConfiguration"
});
// Load additional properties from file
contextProvider.loadPropertiesFromString("config/webapp.properties");
// Add to deployment manager
deploymentManager.addAppProvider(contextProvider);
// Multiple providers for different directories
ContextProvider devProvider = new ContextProvider();
devProvider.setMonitoredDirName("dev-webapps");
devProvider.setEnvironmentName("development");
ContextProvider prodProvider = new ContextProvider();
prodProvider.setMonitoredDirName("prod-webapps");
prodProvider.setEnvironmentName("production");
prodProvider.setExtractWars(false); // Keep WARs compressed in production
deploymentManager.addAppProvider(devProvider);
deploymentManager.addAppProvider(prodProvider);Nested filename filter class for filtering files during directory scanning. Implements sophisticated filtering logic to determine which files and directories should be considered for deployment.
/**
* Filename filter for determining which files should be considered for deployment.
* Accepts WAR files, XML descriptors, and directories while excluding hidden files,
* source control directories, and directories with sibling WAR/XML files.
*/
public class ContextProvider.Filter implements FilenameFilter {
/**
* Filters files for deployment consideration based on comprehensive rules
* @param dir The directory being scanned
* @param name The filename being considered
* @return true if the file should be considered for deployment
*/
public boolean accept(File dir, String name);
}Filter Rules:
Usage Examples:
// The default ContextProvider uses this filter automatically
ContextProvider provider = new ContextProvider();
// Filter is set automatically in constructor: setFilenameFilter(new Filter());
// Custom filter extending the default behavior
ContextProvider customProvider = new ContextProvider() {
{
setFilenameFilter(new FilenameFilter() {
private Filter defaultFilter = new Filter();
@Override
public boolean accept(File dir, String name) {
// Apply default filter first
if (!defaultFilter.accept(dir, name)) {
return false;
}
// Additional custom filtering
if (name.startsWith("temp-")) {
return false; // Exclude temporary deployments
}
return true;
}
});
}
};
// Examples of what the filter accepts/rejects:
// Accepts: "myapp.war", "myapp.xml", "myapp/" (directory)
// Rejects: ".hidden", "temp.d", "cvs", "myapp/" (if myapp.war exists)Install with Tessl CLI
npx tessl i tessl/maven-org-eclipse-jetty--jetty-deploy