Skip to content

Commit f0f2522

Browse files
authored
[jnigen] clarify generation of bindings for built-in Java types (#2641)
This change clarifies that many built-in Java types are now included by default, and provides a clearer example of how to include other classes. It explains that the sources of the Java SDK is no longer required.
1 parent d3c3acb commit f0f2522

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

pkgs/jnigen/README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,26 @@ If the classes are in JAR file, make sure to provide path to JAR file itself, an
186186
If the errors are similar to `symbol not found`, ensure all dependencies of the source are available. If such dependency is compiled, it can be included in `class_path`.
187187

188188
#### Generate bindings for built-in types
189-
To generate bindings for built-in Java types (like those in `java.*` packages), you need to provide the OpenJDK source code to the generator. Here's how:
189+
For your convenience, a number of built-in Java types, for example, many of those in `java.lang` and `java.util`, are provided to your build by `jni` by default.
190190

191-
1. Locate the `src.zip` file in your Java installation directory
192-
2. Extract the `java.base` folder from this zip file
193-
3. Add the path to the extracted `java.base` folder in your `source_path` list in the YAML configuration
191+
Those don't need to be included in the classes block, and will error if you do so, with the following error:
192+
`Fatal: Trying to re-import the generated classes`.
194193

195-
For example, to generate bindings for `java.lang.Math`, your configuration might look like:
194+
For any other types that are in core Java, you can add them in your `classes` block and bindings will be generated when you run the generate bindings task.
195+
196+
Below is a snippet showing how you might generate bindings for several classes in `java.time.*` and a `java.lang` class that is not included by default.
197+
198+
``` yaml
199+
output:
200+
dart:
201+
path: lib/gen/
196202
197-
```yaml
198-
source_path:
199-
- '/path/to/extracted/java.base'
200203
classes:
204+
- 'java.time.Instant'
205+
- 'java.time.ZoneOffset'
206+
- 'java.time.ZonedDateTime'
201207
- 'java.lang.Math'
208+
# - 'java.lang.Integer' # Will error, already included in binary
202209
```
203210

204211
#### How are classes mapped into bindings?

0 commit comments

Comments
 (0)