diff options
author | Tristan Partin <tristan@partin.io> | 2022-03-01 12:05:28 -0600 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2022-03-22 13:21:26 +0200 |
commit | 39f1d52e4a82cc75a4a3a41c3cc17fe2dabdb30b (patch) | |
tree | ec8855a6f7ea0c937736f366258ae8ca2629ea9d /docs/markdown/snippets | |
parent | a559dbe70d113ebaa9bab406e371e54251d66e71 (diff) | |
download | meson-39f1d52e4a82cc75a4a3a41c3cc17fe2dabdb30b.zip meson-39f1d52e4a82cc75a4a3a41c3cc17fe2dabdb30b.tar.gz meson-39f1d52e4a82cc75a4a3a41c3cc17fe2dabdb30b.tar.bz2 |
Add ability to add resources to jars
Previously Meson lacked the ability to add resources to jar files.
Fixes #9945
Diffstat (limited to 'docs/markdown/snippets')
-rw-r--r-- | docs/markdown/snippets/jar-resources.md | 34 |
1 files changed, 34 insertions, 0 deletions
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)) { + // ... +} +``` |