public class Bootstrap extends URLClassLoader
Usually, you need to provide the classpath before invoking the JVM with your
application's main() entry point. With Bootstrap, you use Bootstrap's
main(String[])
instead. All you need to do is provide a base
directory for your jars, and the name of the class with your actual main()
entry point.
But Bootstrap offers another important benefit: it acts as a straightforward hypervisor, letting you bootstrap several applications in the same JVM instance, each with their own "class world." This lets you, in effect, run several applications, either at the same time or in sequence, even if they have overlapping and conflicting classes. The "master" bootstrap singleton provides you with a space of shared classes, allowing the running applications to share data structures.
One important use case for this is to let you "reboot" your application with a new classpath, via a fresh bootstrap, without ever exiting the JVM.
When this class is loaded, it will initialize itself using a property sheet at the "com/threecrickets/boostrap/bootstrap.conf" resource. An example:
main.class = com.threecrickets.sincerity.Sincerity home.property = sincerity.home home.variable = SINCERITY_HOME
Constructor and Description |
---|
Bootstrap(Collection<URL> urls)
Constructor for child bootstraps.
|
Modifier and Type | Method and Description |
---|---|
void |
addFile(File file)
Shortcut to add a file URL to the classpath.
|
void |
addJars(File file)
Recursively adds a directory and all Jar files underneath it to the
classpath.
|
void |
addUrl(URL url)
Adds a URL to the classpath.
|
static void |
bootstrap(Object key,
String[] arguments)
Delegates to your configured main() entry point through any bootstrap.
|
void |
bootstrap(String[] arguments)
Delegates to your configured main() entry point through the bootstrap.
|
static ConcurrentMap<Object,Object> |
getAttributes()
A general-purpose thread-safe location for global static attributes.
|
static Bootstrap |
getBootstrap(Object key)
A bootstrap according to a unique identifying key.
|
static File |
getHome()
The base directory for the master bootstrap.
|
static Bootstrap |
getMasterBootstrap()
The master bootstrap.
|
static void |
main(String[] arguments)
Delegates to your configured main() entry point through the master
bootstrap.
|
static void |
setBootstrap(Object key,
Bootstrap bootstrap) |
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
defineClass, defineClass
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
public Bootstrap(Collection<URL> urls)
urls
- The URLs to add to the classpathpublic static Bootstrap getMasterBootstrap()
public static Bootstrap getBootstrap(Object key)
key
- The key object (must qualify for use as a key in a hashmap)setBootstrap(Object, Bootstrap)
public static void setBootstrap(Object key, Bootstrap bootstrap)
key
- The key object (must qualify for use as a key in a hashmap)bootstrap
- The bootstrapgetBootstrap(Object)
public static ConcurrentMap<Object,Object> getAttributes()
public static File getHome()
public static void main(String[] arguments) throws Exception
arguments
- Arguments to delegate to mainException
- In case of an error during bootstrappingpublic static void bootstrap(Object key, String[] arguments) throws Exception
key
- The key object (must qualify for use as a key in a hashmap)arguments
- Arguments to delegate to mainException
- In case of an error during bootstrappinggetBootstrap(Object)
public void addUrl(URL url)
url
- The URLpublic void addFile(File file)
file
- The fileaddUrl(URL)
public void addJars(File file)
Note that recursion only happens if you add a directory, otherwise it
behaves like addFile(File)
).
file
- The file (special behavior if the file is a directory)Copyright © 2011-2016 Three Crickets LLC.