PomStrap is a hierarchical Class-Loader based on the Maven's artifact repository model. In a nutshell, it provides a runtime feature to Maven.
Maven manages the build of software modules, their documentation, their reporting and the rationalized deployment and storage of the resulting software artifacts. PomStrap is capable - in its simplest form - of loading classes from software artifacts deployed to a Maven repository. It can run embedded within any Java environment that allows the use of custom class-loaders or as primary bootstrap mechanism to run applications ranging from simple command-line applications to complex dynamic enterprise applications.
PomStrap can be configured to access software artifacts from a remote Maven repository via HTTP.
In this section, a brief overview is given on the high level PomStrap use cases.
The PomStrap command line bootstrap allows to run standard Java console applications.
Our first application will print the 'hello world' message to the standard output.
package org.tigris.pomstrap.example.first;
public class Application
implements Runnable
{
public void run()
{
System.out.println( "Hello world!" );
}
public static void main( String[] args )
{
new Application().run();
}
}
Our 'hello world' application has no special requirements or dependency. It is a plain, simple java application.
Conventionally, the name of the main class is Application.
This is the corresponding project metadata.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.tigris.pomstrap</groupId>
<artifactId>org.tigris.pomstrap.example.first</artifactId>
<version>2.X-SNAPSHOT</version>
<name>org.tigris.pomstrap.example.first</name>
</project>
Run Maven to compile and install the application in the local repository.
# mvn install
The class org.tigris.example.first.Application is now part of the artifact org.tigris.pomstrap:org.tigris.pomstrap.example.first:2.X-SNAPSHOT
To run the application, type:
# pom org.tigris.pomstrap:org.tigris.pomstrap.example.first:2.X-SNAPSHOT Hello world!
The command line application tutorial contains detailed information on how to set-up and run command-line applications via PomStrap.
The PomStrap bootstrap is at the core of the PomStrap class-loading mechanism. Given a dependency - the root dependency - the bootstrap loads the implied set of transitive dependencies and builds a class-loader graph.
In the following example, we will show how to instantiate the class of the first example at run-time.
package org.tigris.pomstrap.example.second;
import org.tigris.pomstrap.core.Bootstrap;
import org.tigris.pomstrap.core.BootstrapConfig;
import org.tigris.pomstrap.core.DependencyKey;
public class Application
{
public static void main( String[] args )
throws Exception
{
Bootstrap bootstrap =
new Bootstrap( new BootstrapConfig(),
new DependencyKey( "org.tigris.pomstrap:org.tigris.pomstrap.example.first:2.X-SNAPSHOT" ) );
Class<?> exampleFirstClass =
bootstrap.getRootClassLoader().loadClass( "org.tigris.pomstrap.example.first.Application" );
Runnable exampleFirst = (Runnable) exampleFirstClass.newInstance();
exampleFirst.run();
}
}
This is the corresponding project metadata.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.tigris.pomstrap</groupId>
<artifactId>org.tigris.pomstrap.example.second</artifactId>
<version>2.X-SNAPSHOT</version>
<name>org.tigris.pomstrap.example.second</name>
<dependencies>
<dependency>
<groupId>org.tigris.pomstrap</groupId>
<artifactId>org.tigris.pomstrap.core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Please note that org.tigris.pomstrap.example.second does not have a compile-time dependency on org.tigris.pomstrap.example.first.
The embedded tutorial contains detailed information on how to use PomStrap embedded in applications.
The PomStrap Tomcat Loader allows to run web application directly from a Maven repository. There is no need to manually copy the application WAR to the server where Tomcat runs.
The PomStrap loader org.tigris.pomstrap.tomcat.PomstrapWebappLoader needs to be specified in the Context declaration of the web application to bootstrap directly from a Maven repository.
The Maven repository URL and the authentication credentials can be specified as attributes of the Resources element.
The unpackWAR attribute of the Context must be set to false.
For example, to deploy the test web application org.tigris.pomstrap.test.tomcat.webapp under the context test, the following should we saved to $CATALINA_BASE/conf/catalina/test/ROOT.xml.
<?xml version="1.0" encoding="UTF-8"?>
<Context unpackWAR="false">
<Loader className="org.tigris.pomstrap.tomcat.PomstrapWebappLoader" />
<Resources className="org.tigris.pomstrap.tomcat.PomstrapWarContext"
artifact="org.tigris.pomstrap:org.tigris.pomstrap.test.tomcat.webapp:war:2.X-SNAPSHOT"
repository="http://maven.pomstrap.org" username="repouser" password="repopassword" />
</Context>
The tomcat tutorial contains detailed information on how to set-up and run web applications via PomStrap.