Class DeploymentScanner
- All Implemented Interfaces:
Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
,Scanner.BulkListener
,Scanner.Listener
Jetty WebApp Hot Deployment Scanner.
This class scans one or more directories (typically "webapps") for web applications to deploy, which may be:
- A standard WAR file (must end in ".war")
- A directory containing an expanded WAR file
- A directory containing static content
- An XML descriptor in
XmlConfiguration
format that configures aContextHandler
instance
ContextHandlerFactory
is used to create a ContextHandler
, which is then deployed/undeployed via a Deployer
instance.
The instances of the Deployer
and ContextHandlerFactory
used can either be:
- Passed into a constructor of this class
- Discovered as a {
Container.getBean(Class)
bean} of theServer
instance - Default implementations instantiated by this class.
To avoid double deployments and allow flexibility of the content of the scanned directories, the provider implements some heuristics to ignore some files found in the scans:
- Hidden files (starting with
"."
) are ignored - Directories with names ending in
".d"
are ignored - Property files with names ending in
".properties"
are not deployed. - If a directory and a WAR file exist (eg:
foo/
andfoo.war
) then the directory is assumed to be the unpacked WAR and only the WAR file is deployed (which may reuse the unpacked directory) - If a directory and a matching XML file exist (eg:
foo/
andfoo.xml
) then the directory is assumed to be an unpacked WAR and only the XML file is deployed (which may use the directory in its configuration) - If a WAR file and a matching XML file exist (eg:
foo.war
andfoo.xml
) then the WAR file is assumed to be configured by the XML file and only the XML file is deployed.
For XML configured contexts, the following is available.
- The XML Object ID Map will have a reference to the
Server
instance via the ID name"Server"
- The Default XML Properties are populated from a call to
XmlConfiguration.setJettyStandardIdsAndProperties(Object, Path)
(for things likejetty.home
andjetty.base
) - An extra XML Property named
"jetty.webapps"
is available, and points to the webapps path.
Context Deployment properties will be initialized with:
- The properties set on the application via embedded calls modifying
DeploymentScanner.PathsApp.getAttributes()
- The app specific properties file
webapps/<webapp-name>.properties
- The environment specific properties file
webapps/<environment-name>[-zzz].properties
- The
Attributes
from theEnvironment
To configure Environment specific deployment Attributes
,
either set the appropriate Deployable
attribute via Attributes.setAttribute(String, Object)
,
or use the convenience class DeploymentScanner.EnvironmentConfig
.
DeploymentScanner provider = new DeploymentScanner();
EnvironmentConfig env10config = provider.configureEnvironment("ee10");
env10config.setExtractWars(true);
env10config.setParentLoaderPriority(false);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
static class
Builder of a deployment configuration for a specificEnvironment
.Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer, Dumpable.DumpAppendable
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDeploymentScanner
(Server server) Construct a raw DeploymentScanner that will (periodically) scan specific directories for paths that can be used to construct webapps that will be submitted to theDeployer
for eventual deployment to its configured destination.DeploymentScanner
(Server server, Deployer deployer) Construct a raw DeploymentScanner that will (periodically) scan specific directories for paths that can be used to construct webapps that will be submitted to theDeployer
for eventual deployment to its configured destination.DeploymentScanner
(Server server, Deployer deployer, FilenameFilter filter) Construct a raw DeploymentScanner that will (periodically) scan specific directories for paths that can be used to construct webapps that will be submitted to theDeployer
for eventual deployment to its configured destination.DeploymentScanner
(Server server, Deployer deployer, FilenameFilter filter, ContextHandlerFactory contextHandlerFactory) Construct a raw DeploymentScanner that will (periodically) scan specific directories for paths that can be used to construct webapps that will be submitted to theDeployer
for eventual deployment to its configured destination.DeploymentScanner
(Server server, Deployer deployer, ContextHandlerFactory contextHandlerFactory) Construct a raw DeploymentScanner that will (periodically) scan specific directories for paths that can be used to construct webapps that will be submitted to theDeployer
for eventual deployment to its configured destination. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addWebappsDirectory
(Path dir) configureEnvironment
(String name) Configure the Environment specific Deploy settings.protected void
doStart()
Starts the managed lifecycle beans in the order they were added.protected void
doStop()
Stops the managed lifecycle beans in the reverse order they were added.void
dump
(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.int
boolean
Test if initial scan should be deferred.boolean
IfScanner
is configured toreportRealPaths
.void
pathsChanged
(Map<Path, Scanner.Notification> changeSet) This is the listener event for Scanner to report changes.void
scan()
void
setActionComparator
(Comparator<DeploymentScanner.DeployAction> actionComparator) void
setDeferInitialScan
(boolean defer) Flag to control initial scan behavior.void
void
setEnvironmentsOrder
(List<String> environmentsOrder) void
setScanInterval
(int scanInterval) void
setUseRealPaths
(boolean useRealPaths) TellsScanner
toreportRealPaths
.void
setWebappDirectories
(Collection<Path> directories) toString()
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
Methods inherited from interface org.eclipse.jetty.util.Scanner.BulkListener
filesChanged, pathsChanged
-
Constructor Details
-
DeploymentScanner
Construct a raw DeploymentScanner that will (periodically) scan specific directories for paths that can be used to construct webapps that will be submitted to the
Deployer
for eventual deployment to its configured destination.- Parameters:
server
- the server reference to use for any XML based deployments.
-
DeploymentScanner
Construct a raw DeploymentScanner that will (periodically) scan specific directories for paths that can be used to construct webapps that will be submitted to the
Deployer
for eventual deployment to its configured destination.- Parameters:
server
- the server reference to use for any XML based deployments.deployer
- theDeployer
to use for deploying the createdContextHandler
s, ornull
for a default.
-
DeploymentScanner
public DeploymentScanner(@Name("server") Server server, @Name("deployer") Deployer deployer, @Name("filenameFilter") FilenameFilter filter) Construct a raw DeploymentScanner that will (periodically) scan specific directories for paths that can be used to construct webapps that will be submitted to the
Deployer
for eventual deployment to its configured destination.- Parameters:
server
- the server reference to use for any XML based deployments.deployer
- theDeployer
to use for deploying the createdContextHandler
s, ornull
for a default.filter
- A customFilenameFilter
to control what files theScanner
monitors for changes, ornull
for a default.
-
DeploymentScanner
public DeploymentScanner(@Name("server") Server server, @Name("deployer") Deployer deployer, @Name("contextHandlerFactory") ContextHandlerFactory contextHandlerFactory) Construct a raw DeploymentScanner that will (periodically) scan specific directories for paths that can be used to construct webapps that will be submitted to the
Deployer
for eventual deployment to its configured destination.- Parameters:
server
- the server reference to use for any XML based deployments.deployer
- theDeployer
to use for deploying the createdContextHandler
s, ornull
for a default.contextHandlerFactory
- The factory to use to createContextHandler
s, ornull
for a default.
-
DeploymentScanner
public DeploymentScanner(@Name("server") Server server, @Name("deployer") Deployer deployer, @Name("filenameFilter") FilenameFilter filter, @Name("contextHandlerFactory") ContextHandlerFactory contextHandlerFactory) Construct a raw DeploymentScanner that will (periodically) scan specific directories for paths that can be used to construct webapps that will be submitted to the
Deployer
for eventual deployment to its configured destination.- Parameters:
server
- the server reference to use for any XML based deployments.deployer
- theDeployer
to use for deploying the createdContextHandler
s, ornull
for a default.filter
- A customFilenameFilter
to control what files theScanner
monitors for changes, ornull
for a defaultcontextHandlerFactory
- The factory to use to createContextHandler
s, ornull
for a default.
-
-
Method Details
-
addWebappsDirectory
- Parameters:
dir
- Directory to scan for deployable artifacts
-
configureEnvironment
Configure the Environment specific Deploy settings.- Parameters:
name
- the name of the environment.- Returns:
- the deployment configuration for the
Environment
.
-
dump
Description copied from interface:Dumpable
Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.- Specified by:
dump
in interfaceDumpable
- Overrides:
dump
in classContainerLifeCycle
- Parameters:
out
- The appendable to dump toindent
- The indent to apply after any new lines.- Throws:
IOException
- if unable to write to Appendable
-
getActionComparator
- Returns:
- The
Comparator
used to sort theDeploymentScanner.DeployAction
s before acting on them.
-
setActionComparator
-
getEnvironmentsOrder
-
setEnvironmentsOrder
-
getEnvironmentsDirectory
-
setEnvironmentsDirectory
-
getWebappDirectories
-
setWebappDirectories
-
getScanInterval
@ManagedAttribute("scanning interval to detect changes which need reloaded") public int getScanInterval()- Returns:
- scan interval (in seconds) to detect changes which need reloaded
- See Also:
-
setScanInterval
public void setScanInterval(int scanInterval) - Parameters:
scanInterval
- scan interval (in seconds) to detect changes which need reloaded- See Also:
-
isDeferInitialScan
public boolean isDeferInitialScan()Test if initial scan should be deferred.- Returns:
- true if initial scan is deferred, false to have initial scan occur on startup of
DeploymentScanner
.
-
setDeferInitialScan
public void setDeferInitialScan(boolean defer) Flag to control initial scan behavior.true
- to have initial scan deferred until theServer
component has reached its STARTED state.
Note: any failures in a deployment will not fail the Server startup in this mode.false
- (default value) to have initial scan occur as normal onDeploymentScanner
startup.
- Parameters:
defer
- true to defer initial scan, false to have initial scan occur on startup ofDeploymentScanner
.
-
isUseRealPaths
public boolean isUseRealPaths()IfScanner
is configured toreportRealPaths
.- Returns:
- True if the real path of the scanned files should be used for deployment.
- See Also:
-
setUseRealPaths
public void setUseRealPaths(boolean useRealPaths) TellsScanner
toreportRealPaths
.- Parameters:
useRealPaths
- True if the real path of the scanned files should be used for deployment.- See Also:
-
pathsChanged
This is the listener event for Scanner to report changes.- Specified by:
pathsChanged
in interfaceScanner.BulkListener
- Parameters:
changeSet
- the changeset from the Scanner.
-
scan
-
doStart
Description copied from class:ContainerLifeCycle
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classContainerLifeCycle
- Throws:
Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
Description copied from class:ContainerLifeCycle
Stops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStop
in classContainerLifeCycle
- Throws:
Exception
- If there was a problem stopping. Will cause a transition to FAILED state
-
toString
- Overrides:
toString
in classAbstractLifeCycle
-