Singularity is a Maven packaging format for self-contained executable jars with all their dependencies. Notably, a Singularity package does not unpack and repack its dependencies. The original jar files are maintained, and their namespaces are preserved. The Singularity package will contain a boot class loader that understands the jar within jar format. In order to speed class resolution and loading, offset indexes of entries within the jar library dependencies are built during package construction. There should be nothing special you need to do with your code to create a Singularity from it, other than defining the packaging and nominating a public static void main (String… args)
entry point.
Tip
|
Code looking to obtain a class loader should use… Thread.currentThread().getContextClassLoader(); …as the system class loader will not understand the jar within jar packaging format. |
In order to have Maven create a self-contained jar you should declare the packaging as singularity
and include the spark-singularity-maven-plugin
as outlined below..
<project>
...
<packaging>singularity</packaging>
...
<build>
<plugins>
<plugin>
<groupId>org.smallmind</groupId>
<artifactId>spark-singularity-maven-plugin</artifactId>
<version>LATEST</version>
<extensions>true</extensions>
<configuration>
<mainClass><!-- entry point class containing a main() method --></mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
The following configuration attributes are supported by the plugin…
-
mainClass (required) - An entry point class containing a standard
public static void main (String… args)
method.Example<mainClass>my.Main</mainClass>
-
skip (optional, defaults to false) - If this attribute exists and is set
true
, then the plugin will skip its operations and no artifact will be produced.Example<skip>true</skip>