= Extending CRaSH

== Embedding CRaSH

The chapter <<running_crash>> explains how to run CRaSH as a standalone or an embedded service. We will study in this section the technical
aspect of running application and show how CRaSH can be embedded in specific environments.

The root class for reusing CRaSH is the +org.crsh.plugin.PluginLifeCycle+ class. This class is abstract and it cannot
be used directly, instead it should be subclasses for providing specific behavior for running CRaSH. There are several
subclasses using it:

* The standalone bootstrap with the +org.crsh.standalone.Bootstrap+ class : designed for using CRaSH with a real
file system (i.e +java.io.File+). It defines a specific layout for locating resources (libraries, configuration and commands).
* The embedded approaches
** +org.crsh.plugin.WebPluginLifeCycle+ : uses a +javax.servlet.ServletContext+
** +org.crsh.spring.SpringBootstrap+ : embeds CRaSH as a Spring bean
** +org.crsh.spring.SpringWebBootstrap+ : extends the +SpringBootstrap+ and uses the existing +ServletContext+

[[standalone_bootstrap]]
=== Standalone bootstrap

The +org.crsh.standalone.Bootstrap+ class is a generic class that can be used to embed the shell in your Java programs
Its usage is quite straighforward and configurable. The bootstrap is a coarse grained approach and it needs a bit of configuration for running:

* The +baseLoader+ properties is the +java.lang.ClassLoader+ used by CRaSH for loading plugins, resources or command sources (under the
_/crash/commands/_ path. This property is not modifiable and must be provided when the bootstrap is instantiated.
* The +config+ properties provides the contextual properties used by CRaSH configuration such as _crash.vfs.refresh_period_
* The +attributes+ property provides the contextual attributes used by CRaSH available at runtime via the +org.crsh.command.CommandContext+,
it is useful for providing objects to commands in a similar fashion to servlet context attributes
* The +cmdPath+ property is a list of +java.io.File+ scanned by CRaSH for loading additional commands
* The +confPath+ property is a list of +java.io.File+ scanned by CRaSH for loading configuration files

Let's see an example on how to use it

=== Standalone CRaSH

The standalone shell is a Java class configurable and runnable from the command line that is used by the standalone distribution. It is
built upon the <<standalone_bootstrap>>.
