You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -686,35 +686,9 @@ For example, to allow serialization of `org.apache.spark.SparkContext$$anonfun$h
686
686
}
687
687
```
688
688
689
-
## Defining Classes at Run Time
690
-
691
-
Java has support for loading new classes from bytecode at run time, which is not possible in Native Image as all classes must be known at build time (the "closed-world assumption").
692
-
693
-
To emulate class loading, the [Native Image Agent](AutomaticMetadataCollection.md) can trace dynamically loaded classes and save their bytecode for later use by the `native-image` builder.
694
-
At runtime, if there is an attempt to load a class with the same name and bytecode as one of the classes encountered during tracing, the predefined class will be supplied to the application.
695
-
696
-
> Note: Predefined classes metadata is not meant to be manually written.
697
-
698
-
Predefined classes metadata should be specified in a _predefined-classes-config.json_ file and conform to the JSON schema defined in
@@ -784,7 +758,37 @@ See below is a sample reachabilIty metadata configuration that you can use in _r
784
758
}
785
759
```
786
760
787
-
### Further Reading
761
+
## Defining Classes at Run Time
762
+
763
+
Java has support for loading new classes from bytecode at run time, which is not possible in Native Image as all classes must be known at build time (the "closed-world assumption").
764
+
To overcome this issue there are the following options:
765
+
1. Modify or reconfigure your application (or a third-party library) so that it does not generate classes at runtime or load them via non-built-in class loaders.
766
+
2. If the classes must be generated, try to generate them at build time in a static initializer of a dedicated class.
767
+
The generated java.lang.Class objects should be stored in static fields and the dedicated class initialized by passing `--initialize-at-build-time=<class_name>` as the build argument.
768
+
3. If none of the above is applicable, use the [Native Image Agent](AutomaticMetadataCollection.md) to run the application and collect predefined classes with
At runtime, if there is an attempt to load a class with the same name and bytecode as one of the classes encountered during tracing, the predefined class will be supplied to the application.
771
+
772
+
Predefined classes metadata is specified in a _predefined-classes-config.json_ file and conform to the JSON schema defined in
0 commit comments