JVM | Platform | Status |
---|---|---|
OpenJDK (Temurin) Current | Linux | |
OpenJDK (Temurin) LTS | Linux | |
OpenJDK (Temurin) Current | Windows | |
OpenJDK (Temurin) LTS | Windows |
The jade
package provides an API for following good application directory
etiquette.
- API for handling application data directories.
- Implements the XDG Basedir specification on Unix-like platforms.
- Implements best-practice directory management on Windows platforms.
- Support for portable applications.
- High-coverage automated test suite.
- Written in pure Java 17.
- OSGi-ready.
- JPMS-ready.
- ISC license.
Applications use jade
via the com.io7m.jade.api
module, but should also
have the com.io7m.jade.vanilla
module on the class/module path. If the
com.io7m.jade.vanilla
module is not available, the jade
package
will unconditionally return paths equivalent those returned by
portable mode.
The jade
package selects a set of application paths based on the current
operating system and the given configuration information. Getting access to the
basic set of application directories for an application named Widget
is
straightforward:
final var configuration =
ApplicationDirectoryConfiguration.builder()
.setApplicationName("Widget")
.build();
final var directories =
ApplicationDirectories.get(configuration);
System.out.println("Configuration directory: " + directories.configurationDirectory());
System.out.println("Data directory: " + directories.dataDirectory());
System.out.println("Cache directory: " + directories.cacheDirectory());
Applications, particularly on Windows, often want to run in portable mode. Portable mode essentially means that all of the paths used by the application are given relative to the initial working directory of the application. This is typically used to facilitate running applications from removable USB storage devices without saving any data to the host operating system storage.
The jade
API allows for specifying the name of a system property that will be
consulted in order to determine if the application wants to run in portable
mode. If the named system property has a value parsed as true
, the API will
return paths relative to the application rather than system-specific paths.
final var configuration =
ApplicationDirectoryConfiguration.builder()
.setApplicationName("Widget")
.setPortablePropertyName("com.io7m.example.portable")
.build();
System.setProperty("com.io7m.example.portable", "true");
final var directories =
ApplicationDirectories.get(configuration);
System.out.println("Configuration directory: " + directories.configurationDirectory());
System.out.println("Data directory: " + directories.dataDirectory());
System.out.println("Cache directory: " + directories.cacheDirectory());
The jade
API allows for specifying the name of a system property that will be
consulted in order to determine if the application wants to override the
directory used to calculate application directories. If the named system
property exists, the value of the property will be treated as a path, and all
application directories will be calculated relative to this path.
final var configuration =
ApplicationDirectoryConfiguration.builder()
.setApplicationName("Widget")
.setOverridePropertyName("com.io7m.example.override")
.build();
System.setProperty("com.io7m.example.override", "/tmp/x");
final var directories =
ApplicationDirectories.get(configuration);
// Prints: /tmp/x/config
System.out.println("Configuration directory: " + directories.configurationDirectory());
// Prints: /tmp/x/data
System.out.println("Data directory: " + directories.dataDirectory());
// Prints: /tmp/x/cache
System.out.println("Cache directory: " + directories.cacheDirectory());