public class ReflectionConfigGenerator extends Object
ReflectionConfigGeneratorgenerates a JSON String with the program elements that will be accessed reflectively in a picocli-based application, in order to compile this application ahead-of-time into a native executable with GraalVM.
GraalVM has limited support for Java reflection and it needs to know ahead of time the reflectively accessed program elements.
The output of
ReflectionConfigGeneratoris intended to be passed to the
-H:ReflectionConfigurationFiles=/path/to/reflect-config.jsonoption of the
native-imageGraalVM utility. This allows picocli-based applications to be compiled to a native image.
Alternatively, the generated configuration files can be supplied to the
native-imagetool by placing them in a
META-INF/native-image/directory on the class path, for example, in a JAR file used in the image build. This directory (or any of its subdirectories) is searched for files with the names
resource-config.json, which are then automatically included in the build. Not all of those files must be present. When multiple files with the same name are found, all of them are included.
If necessary, it is possible to exclude classes with system property
picocli.codegen.excludes, which accepts a comma-separated list of regular expressions of the fully qualified class names that should not be included in the resulting JSON String.
Constructors Constructor Description
All Methods Static Methods Concrete Methods Modifier and Type Method Description
generateReflectionConfig(CommandLine.Model.CommandSpec... specs)Returns a JSON String with the program elements that will be accessed reflectively for the specified
main(String... args)Runs this class as a standalone application, printing the resulting JSON String to a file or to
public static void main(String... args)Runs this class as a standalone application, printing the resulting JSON String to a file or to
args- one or more fully qualified class names of
public static String generateReflectionConfig(CommandLine.Model.CommandSpec... specs) throws ExceptionReturns a JSON String with the program elements that will be accessed reflectively for the specified
specs- one or more
CommandSpecobjects to inspect
- a JSON String in the format
required by the
-H:ReflectionConfigurationFiles=/path/to/reflect-config.jsonoption of the GraalVM
NoSuchFieldException- if a problem occurs while processing the specified specs
IllegalAccessException- if a problem occurs while processing the specified specs