From 39f1d52e4a82cc75a4a3a41c3cc17fe2dabdb30b Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Tue, 1 Mar 2022 12:05:28 -0600 Subject: Add ability to add resources to jars Previously Meson lacked the ability to add resources to jar files. Fixes #9945 --- docs/markdown/snippets/jar-resources.md | 34 +++++++++++++++++++++++++++++++++ docs/yaml/functions/jar.yaml | 4 ++++ 2 files changed, 38 insertions(+) create mode 100644 docs/markdown/snippets/jar-resources.md (limited to 'docs') diff --git a/docs/markdown/snippets/jar-resources.md b/docs/markdown/snippets/jar-resources.md new file mode 100644 index 0000000..12b0c81 --- /dev/null +++ b/docs/markdown/snippets/jar-resources.md @@ -0,0 +1,34 @@ +## JAR Resources + +The ability to add resources to a JAR has been added. Use the `java_resources` +keyword argument. It takes a `sturctured_src` object. + +```meson +jar( + meson.project_name(), + sources, + main_class: 'com.mesonbuild.Resources', + java_resources: structured_sources( + files('resources/resource1.txt'), + { + 'subdir': files('resources/subdir/resource2.txt'), + } + ) +) +``` + +To access these resources in your Java application: + +```java +try (InputStreamReader reader = new InputStreamReader( + Resources.class.getResourceAsStream("/resource1.txt"), + StandardCharsets.UTF_8)) { + // ... +} + +try (InputStreamReader reader = new InputStreamReader( + Resources.class.getResourceAsStream("/subdir/resource2.txt"), + StandardCharsets.UTF_8)) { + // ... +} +``` diff --git a/docs/yaml/functions/jar.yaml b/docs/yaml/functions/jar.yaml index 6e8e5dd..52f66e5 100644 --- a/docs/yaml/functions/jar.yaml +++ b/docs/yaml/functions/jar.yaml @@ -14,3 +14,7 @@ kwargs: main_class: type: str description: Main class for running the built jar + java_resources: + type: structured_src + since: 0.62.0 + description: Resources to be added to the jar -- cgit v1.1