Embedded

Java ships with a standard network class-loader: URLClassLoader. Unfortunately the current implementation of this class-loader suffers from two major issues. Its capability to access remote jars via HTTP is both slow and unreliable. Moreover, it does not easily allow for classes to be confined and managed into separate units.

The pomstrap bootstrap builds a class-loader graph that reflects the dependency relationships represented by Maven artifact dependencies. The set of dependencies for a given artifact are defined within a project descriptor.

The use of a class-loader tree - rather than a 'catch-all' class-loader - allows for having multiple versions of the same artifact - that typically implies having multiple versions of the same class - within the same JVM. TODO ref jar-hell-article

The following snippet shows how to create a PomStrap boostrap instance given two key properties: a Maven software repository and a dependency key object.

BootstrapConfig bootstrapConfig = new BootstrapConfig();
bootstrapConfig.setRepositoryUrl( "http://content/groups/public" );
Bootstrap bootstrap = new Bootstrap( bootstrapConfig , new DependencyKey( "org.tigris:org.tigris.example.helloworld:TRUNK-SNAPSHOT" ) );

If no repository is specified, pomstrap will use the local repositories located at $HOME/.m2/repository.

Bootstrap bootstrap = new Bootstrap(
  new BootstrapConfig(),
  new DependencyKey( "org.tigris.pomstrap:org.tigris.pomstrap.example.first:2.X-SNAPSHOT" ) 
);

The helper method public void run( String[] args ) allows to to run the default application in way similar to the pomstrap cli utility.

bootstrap.run( new String[]{} );

In order to execute the main method of a generic class, the overloaded helper method

public void run( String className, String[] args )

allows to specify a generic class name, e.g.:

bootstrap.run( "org.tigris.example.helloworld.Hi", new String[]{ "Alessandro" } );

The full capabilities of PomStrap can be unleashed by directly using the tree - to be precise graph - of class-loaders.

Any class can be instantiated using the standard ClassLoader factory methods.

For example, to create an instance of the class FirstJob that implements the interface Runnable, we can write

TODO review example

Class clazz = (Runnable) bootstrap.getRootClassLoader().loadClass( "...FirstJob" );
clazz.job.run();

Showing the dependency tree

bootstrap.getRootClassLoader().printDepencencyTree( System.out );

It will produce the following tree:

TODO