Class ClasspathConfiguration

java.lang.Object
is.codion.tools.jul.classpath.ClasspathConfiguration

public final class ClasspathConfiguration extends Object
A custom configuration class for java.util.logging that loads configuration files from the classpath.

By default, java.util.logging only supports loading configuration files from the filesystem via -Djava.util.logging.config.file=path/to/file.properties. This limitation makes it difficult to use JUL configuration in containerized applications, jlink images, or fat jars where configuration files are typically packaged as classpath resources.

This class bridges that gap by loading the configuration file specified by java.util.logging.config.file from the classpath instead of the filesystem. It uses the standard JUL configuration mechanism via -Djava.util.logging.config.class to install itself as the configuration handler.

Module Path Requirements

This class is in the is.codion.tools.jul.classpath module, which must be on the module path for the JVM to load it. There are two ways to ensure this:

Add a requires clause to your module-info.java:


 module your.module {
     requires is.codion.tools.jul.classpath;
 }
 

Note: The is.codion.framework.server module already requires this module, so server applications using EntityServer get this functionality automatically without additional configuration.

Option 2: Runtime Module Addition

If you cannot add a module dependency (e.g., configuration-only modules with no module-info.java), explicitly add the module at runtime:


 --add-modules is.codion.tools.jul.classpath
 

For jlink images, add the module to the jlink configuration:


 jlink --add-modules is.codion.tools.jul.classpath,...
 

Basic Usage

Place your logging configuration file (e.g., logging.properties) on the classpath and configure the JVM with both properties:


 -Djava.util.logging.config.file=logging.properties
 -Djava.util.logging.config.class=is.codion.tools.jul.classpath.ClasspathConfiguration
 

The configuration file will be loaded from the classpath root using the context class loader.

Example Configuration File

A typical use case is configuring serialization filter rejection logging:


 # logging.properties - place on classpath

 # Global log level
 .level=OFF

 # Enable java.io.serialization logger
 java.io.serialization.level=FINE
 java.io.serialization.handlers=java.util.logging.FileHandler
 java.io.serialization.useParentHandlers=false

 # Write to file in working directory
 java.util.logging.FileHandler.pattern=serialization.log
 java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
 java.util.logging.SimpleFormatter.format=%1$tF %1$tT %4$s: %5$s%n
 

Benefits

  • Works with jlink images where filesystem access may be restricted
  • Compatible with Docker containers and cloud deployments
  • Enables packaging JUL configuration in fat jars
  • Maintains standard java.util.logging.config.file property semantics
  • Provides clear feedback on success or failure to load configuration
See Also:
  • Constructor Details

    • ClasspathConfiguration

      public ClasspathConfiguration()
      Constructs a new ClasspathConfiguration and immediately loads the configuration file specified by java.util.logging.config.file from the classpath.

      This constructor is invoked automatically by the JVM when -Djava.util.logging.config.class=is.codion.tools.jul.classpath.ClasspathConfiguration is specified.

      If the configuration file is found and successfully loaded, a confirmation message is printed to stdout. If the file is not found or loading fails, an error message is printed to stderr.