Class ReflectionConfigGenerator
- java.lang.Object
-
- picocli.codegen.aot.graalvm.ReflectionConfigGenerator
-
public class ReflectionConfigGenerator extends java.lang.ObjectReflectionConfigGeneratorgenerates 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 thenative-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 aMETA-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 namesjni-config.json,reflect-config.json,proxy-config.jsonandresource-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.- Since:
- 3.7.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classReflectionConfigGenerator.App(package private) static classReflectionConfigGenerator.ReflectedClass(package private) static classReflectionConfigGenerator.ReflectedField(package private) static classReflectionConfigGenerator.ReflectedMethod(package private) static classReflectionConfigGenerator.Visitor
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringREFLECTED_BINDING_FIELD_SCOPEprivate static java.lang.StringREFLECTED_FIELD_BINDING_CLASSprivate static java.lang.StringREFLECTED_FIELD_BINDING_FIELDprivate static java.lang.StringREFLECTED_METHOD_BINDING_CLASSprivate static java.lang.StringREFLECTED_METHOD_BINDING_METHODprivate static java.lang.StringREFLECTED_PROXY_METHOD_BINDING_CLASSprivate static java.lang.StringSYSPROP_CODEGEN_EXCLUDES
-
Constructor Summary
Constructors Constructor Description ReflectionConfigGenerator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringBuildergenerateReflectionConfig(ReflectionConfigGenerator.Visitor visited)static java.lang.StringgenerateReflectionConfig(CommandLine.Model.CommandSpec... specs)Returns a JSON String with the program elements that will be accessed reflectively for the specifiedCommandSpecobjects.static voidmain(java.lang.String... args)Runs this class as a standalone application, printing the resulting JSON String to a file or toSystem.out.
-
-
-
Field Detail
-
SYSPROP_CODEGEN_EXCLUDES
private static final java.lang.String SYSPROP_CODEGEN_EXCLUDES
- See Also:
- Constant Field Values
-
REFLECTED_FIELD_BINDING_CLASS
private static final java.lang.String REFLECTED_FIELD_BINDING_CLASS
- See Also:
- Constant Field Values
-
REFLECTED_METHOD_BINDING_CLASS
private static final java.lang.String REFLECTED_METHOD_BINDING_CLASS
- See Also:
- Constant Field Values
-
REFLECTED_PROXY_METHOD_BINDING_CLASS
private static final java.lang.String REFLECTED_PROXY_METHOD_BINDING_CLASS
- See Also:
- Constant Field Values
-
REFLECTED_FIELD_BINDING_FIELD
private static final java.lang.String REFLECTED_FIELD_BINDING_FIELD
- See Also:
- Constant Field Values
-
REFLECTED_METHOD_BINDING_METHOD
private static final java.lang.String REFLECTED_METHOD_BINDING_METHOD
- See Also:
- Constant Field Values
-
REFLECTED_BINDING_FIELD_SCOPE
private static final java.lang.String REFLECTED_BINDING_FIELD_SCOPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
main
public static void main(java.lang.String... args)
Runs this class as a standalone application, printing the resulting JSON String to a file or toSystem.out.- Parameters:
args- one or more fully qualified class names of@Command-annotated classes.
-
generateReflectionConfig
public static java.lang.String generateReflectionConfig(CommandLine.Model.CommandSpec... specs) throws java.lang.Exception
Returns a JSON String with the program elements that will be accessed reflectively for the specifiedCommandSpecobjects.- Parameters:
specs- one or moreCommandSpecobjects to inspect- Returns:
- a JSON String in the format
required by the
-H:ReflectionConfigurationFiles=/path/to/reflect-config.jsonoption of the GraalVMnative-imageutility. - Throws:
java.lang.NoSuchFieldException- if a problem occurs while processing the specified specsjava.lang.IllegalAccessException- if a problem occurs while processing the specified specsjava.lang.Exception
-
generateReflectionConfig
private static java.lang.StringBuilder generateReflectionConfig(ReflectionConfigGenerator.Visitor visited)
-
-