Bootstrap

Goal

The goal of the bootstrap module is to create the initial environment for a server. Normally this sort of bootstrap is handled by java directly via command line arguments to the java executable or via manifest entries in an executable jar. Unfortunately, the bootstrap built into Java is so limited and hard to work with that it is often augmented with shell scripts to generate the command line arguments. The xbean-bootstrap module will support the following features:

  • Creation of a bootstrap class loader which is a child of the system class loader. This leaves the system class loader clean of the bootstrap classes, which makes class loader isolation much easier.
  • Support for ant style pattern matching for the specification of the bootstrap class path. Normally one writes a shell script to find all jars and zips in the lib directory, or one has to list the exact name of each jar.
  • Pluggable bootstrap loaders. The bootstrap code determines what should be loaded (normally this is a file but is it really just a string so anything goes), and finds loader that can handle the resource (this will normally be the spring loader).
  • Bootstrap jar should be reusable. In most cases, the default values should be good enough for a server. In cases where defaults need to be changed, the manifest can be modified to change them.
  • Bootstrap should be completely self contained meaning no dependencies.
  • Bootstrap should do as little as possible. Create the class loader, create the loader, start the loading, and get out of the way.

Properties

The bootstrap code will need a bunch of properties to start up, and there are many way to get properties into the server. This is a little something I learned from OpenEJB is we load properties in layers from multiple sources and then present the final startup code with a single properties object.

Another trick from OpenEJB is the system properties on the command line come from the left side of the java class name and to make life easy you also scan the command line args for aditional -Dname=value properties. Then you just add those properties to the system making the admin's life easier.

  1. System properties
  2. bin/bootstrap.properties
  3. META-INF/bootstrap.properties

Property

Default

Description

xbean.base.dir

if can locate startup jar or startup classes dir (the one containing a the bootstrap class)
if startup jar is named "bin" use parent else use startup jar
else throw error

The base directory of the server. This is simply set into the environment.

xbean.bootstrap.ClassPath

lib/*.jar lib*.zip

The paths used for the bootstrap class loader.

xbean.bootstrap.ClassLoaderFactory

UrlClassLoaderFactory

The factory used to create the bootstrap class loader.

xbean.bootstrap.Loader

Use xbean-finder to search class path for file named META-INF/org/xbean/bootstrap/loader.properties

The class used to load the bootstrap resource

Startup Procedure

  1. Process properties
    1. determine base dir and set into system property xbean.base.dir
    2. determine class path
    3. determine class loader factory
    4. determine the bootstrap loader
  2. Resolve class path
  3. Create class loader
  4. Create the bootstrap loader
  5. Call loader passing in the class loader, properties, and cli args (without any consumed during bootstrap)
  • No labels