Stowaway JARs API Reference
Configuration
Stowaways are configured in the Spaceport manifest file (.spaceport) under the stowaways key.
stowaways.enabled
| Property | Value |
|---|---|
| Type | boolean |
| Default | true |
| Required | No |
Enables or disables stowaway JAR loading. When false, the entire stowaway system is skipped at startup.
stowaways:
enabled: false
stowaways.paths
| Property | Value |
|---|---|
| Type | List<String> |
| Default | ["stowaways/*"] |
| Required | No (when enabled is true) |
A list of directory paths to scan for JAR files. Each path can be either relative (resolved from the Spaceport project root) or absolute.
stowaways:
enabled: true
paths:
- "stowaways/*"
- "lib/drivers/"
- "/opt/shared-jars/*"
Wildcard Scanning
Paths ending with * enable recursive subdirectory scanning. Paths without * scan only the immediate directory.
| Path Pattern | Behavior |
|---|---|
stowaways/* |
Scans stowaways/ and all nested subdirectories recursively |
lib/external/ |
Scans only the lib/external/ directory (no subdirectories) |
/opt/jars/* |
Scans the absolute path /opt/jars/ and all subdirectories |
JAR files are identified by the .jar extension (case-insensitive).
Runtime Configuration (Internal)
stowaways.'jar urls'
| Property | Value |
|---|---|
| Type | URL[] |
| Set by | Stowaways.load() |
| Consumed by | SourceStore |
After loading, the Stowaways system stores the resolved JAR URLs in Spaceport.config.stowaways.'jar urls'. This array is consumed by SourceStore when it creates the GroovyClassLoader for source module compilation, ensuring that stowaway classes are available for imports in source modules.
This is an internal configuration value. Application code should not read or modify it.
Classes
spaceport.engineering.Stowaways
The main class responsible for discovering and loading stowaway JAR files.
Package: spaceport.engineering
static void load()
Entry point for the stowaway loading process. Called during Spaceport startup, after configuration is loaded and before source modules are compiled.
Behavior:
- Initializes
Spaceport.classLoaderif it has not been set (uses the current thread's context classloader or the Stowaways class's own classloader as a fallback). - Checks
stowaways.enabledin config. Returns immediately if disabled. - Checks
stowaways.pathsin config. Returns immediately if no paths are defined. - Determines whether the configuration is the default (
['stowaways/*']) to control error handling behavior. - Iterates over each path in
stowaways.paths, callingscanForJars()to collect JAR files. - Passes the collected JAR files to
loadJarFiles().
Configuration required:
Spaceport.config.stowaways.enabledmust betrueSpaceport.config.stowaways.pathsmust contain at least one path
private static List<File> scanForJars(String pathPattern, boolean isDefaultConfig)
Scans a single directory path for JAR files.
| Parameter | Type | Description |
|---|---|---|
pathPattern |
String |
Directory path to scan. May end with * for recursive scanning. |
isDefaultConfig |
boolean |
Whether the current configuration is the default. Controls error handling. |
Returns: List<File> — all JAR files found in the specified directory.
Behavior:
- If the path ends with
*, strips the*and enables recursive scanning. - Converts relative paths to absolute paths using
Spaceport.config.'spaceport root'as the base. - Checks if the directory exists:
- Default config: silently returns an empty list if missing.
- Custom config: prints an error and calls
System.exit(1).
- Validates the path is a directory (not a file). Exits on failure regardless of config type.
- Scans for files with a
.jarextension (case-insensitive):- Recursive mode: uses
eachFileRecurseto traverse subdirectories. - Non-recursive mode: uses
eachFilefor the immediate directory only.
- Recursive mode: uses
private static void loadJarFiles(List<File> jarFiles, boolean isDefaultConfig)
Loads discovered JAR files into the classloader chain.
| Parameter | Type | Description |
|---|---|---|
jarFiles |
List<File> |
JAR files to load. |
isDefaultConfig |
boolean |
Whether the current configuration is the default. |
Behavior:
- If the list is empty, prints a message and returns.
- Converts all
Fileobjects toURLobjects viafile.toURI().toURL(). - Stores the URL array in
Spaceport.config.stowaways.'jar urls'for later use bySourceStore. - Creates a new
URLClassLoaderwith all JAR URLs, using the currentSpaceport.classLoaderas the parent. - Replaces
Spaceport.classLoaderwith the newURLClassLoader.
Classloader Architecture
Stowaways use a layered classloader design to ensure JARs persist across source module reloads:
Thread Context ClassLoader (or Stowaways.class ClassLoader)
└── URLClassLoader (stowaway JARs) <-- Spaceport.classLoader
└── GroovyClassLoader (source modules) <-- Created by SourceStore
When source modules are reloaded, SourceStore creates a new GroovyClassLoader that uses Spaceport.classLoader (the stowaway URLClassLoader) as its parent. This means:
- Stowaway classes are always available to source modules via standard
importstatements. - Stowaway JARs do not need to be reloaded when source modules change.
- The stowaway classloader is created once at startup and remains for the application lifecycle.
Additionally, SourceStore adds the stowaway JAR URLs directly to the GroovyClassLoader via addURL(). This ensures that the Groovy compiler can resolve classes from stowaway JARs during compilation, not just at runtime.
Error Behavior Summary
| Condition | Default Config | Custom Config |
|---|---|---|
| Directory does not exist | Debug log, continue | Error, System.exit(1) |
| Path is not a directory | Error, System.exit(1) |
Error, System.exit(1) |
| No JARs found in directories | Prints message, continue | Prints message, continue |
| Feature disabled | Debug log, skip | Debug log, skip |
| No paths defined | Debug log, skip | Debug log, skip |
Make the docs better.Edit this page on GitHub