Projects using Java 9+

Special considerations with Java 9 and Above

With Java 9 and the introduction of Jigsaw and the module system, Java no longer allows arbitrary reflection: If a module or a package is not open, its not possible to use reflection to inspect private members of the classes in the module.

AndHow uses reflection to get live references to AndHow Properties declared in your classes, even those declared as private. Without the ability to reflect into your application code, AndHow can't do its job.

The good news is that AndHow has been tested and works on Java 9 - Java 15 for projects that do not use Java modules . AndHow should work on Java 9+ projects that use modules as outlined below. The next major release of AndHow will switch to using the Java module system so that AndHow can be explicitly allowed to access private modules via the opens to mechanism.

There are three solutions to the module conundrum, all of which are easily workable in most cases.

1) Simply don't use modules

The main feature of Jigsaw modules is that it allowed the JDK to be distributed in smaller pieces with smaller runtimes. Applications, especially those that runs as cloud lambdas, micro-services or within containers, live in a very walled garden. The extra level of ceremony that Jigsaw modules provides (essentially protecting your code from itself and the dependencies you choose to use) doesn't really add any meaningful security. If you don't declare modules, there is nothing more you need to do.

2) Place all of your AndHow Properties in a dedicated Module or Package that is open

If you consolidate your AndHow Properties to a single package or module, you can declare it open:

To open an entire Module:

open module my.project.mymodule {

}

To open just one package in a Module:

module my.project.mymodule {

opens com.model;

}

3) Make your AndHow Properties public or protected in public classes, and export the package

To export a package in a Module:

module my.project.mymodule {

exports com.model;

}

AndHow Property example:

package com.model

public MyConfig {

protected static final StrProp MY_PROP = StrProp.builder().mustBeNonNull().build();

}