When using a native-image.properties containing the following
Args = -H:ResourceConfigurationFiles=${.}/resources-config.json
and resources-config.json containing a standard like
{
"resources": [
{
"pattern": ".*greeting.txt$"
}
]
}
native-image fails as it try to resolve the resources-config.json with an absolute path outside the jar:
native-image -jar target/native-story-1.0-SNAPSHOT.jar
Error: Invalid Path entry META-INF/native-image/resources-config.json
Caused by: java.nio.file.NoSuchFileException: /Users/msimons/Projects/tmp/reflection-config/META-INF/native-image/resources-config.json
Attached you will find a reproducer:
mvn clean package && native-image -jar target/native-story-1.0-SNAPSHOT.jar
Removing the native-image.properties and building like this
mvn clean package && native-image -jar target/native-story-1.0-SNAPSHOT.jar -H:ResourceConfigurationFiles=src/main/resources/META-INF/native-image/resources-config.json
works.
Expectation
ResourceConfigurationFiles should be resolved correctly via ${.} similar to the other config files.
While https://www.graalvm.org/reference-manual/native-image/Resources/ states
The configuration file鈥檚 path must be provided to native-image with -H:ResourceConfigurationFiles=/path/to/resource-config.json.
I don't see any exclusion that the wild card won't work on the documentation of native-image.properties. If that is the case, than this doc https://www.graalvm.org/reference-manual/native-image/Configuration/ should clearly state it.
You have to use Option -H:ResourceConfigurationResources instead of -H:ResourceConfigurationFiles if you want to refer to a Java resource location (which is what you are trying to do here).
> native-image --expert-options | grep ResourceConfiguration
-H:ResourceConfigurationFiles=... Files describing Java resources to be included in the image. Default: None
-H:ResourceConfigurationResources=... Resources describing Java resources to be included in the image. Default: None
Awesome!! And makes totally sense when you got point to it. My bad.
That would be a nice addition to the docs, though.
Should I close this then?
That would be a nice addition to the docs, though.
Were would you suggest to add this info in our docs? cc @olyagpl
Here: https://www.graalvm.org/reference-manual/native-image/Resources/
I just copied and pasted -H:ResourceConfigurationFiles.
Of course, I could have read more carefully and the docs are accurate as is.
Helpful would be something like
"For configuration inside your rresources use the ResourceConfigurationResources form.
Or as a general block atop https://www.graalvm.org/reference-manual/native-image/Configuration/#properties-file-format
"Configuration can be provided both as resources inside your artifact or as external file. For internal resources, use XXXConfigurationResource, for external files XXXConfigurationFiles"
It's obvious when you are aware of the both ways, but not upfront.
It's obvious when you are aware of the both ways, but not upfront.
@michael-simons thanks for the suggestions. I will add something like that.
@olyagpl please provide the following patch to our documentation.
--- substratevm/Configuration.md (revision 9c2851fedea1e0ba615189d6b2823061a7658b83)
+++ substratevm/Configuration.md (date 1600183477480)
@@ -37,6 +37,15 @@
useful if the native-image.properties file wants to refer to resources within
its "subfolder", for example,
`-H:SubstitutionResources=${.}/substitutions.json`.
+Always make sure to use the option variants that take resources. I.e. Use
+`-H:ResourceConfigurationResources` instead of `-H:ResourceConfigurationFiles`.
+Other options that are known to work in this context are:
+
+* `-H:DynamicProxyConfigurationResources`
+* `-H:JNIConfigurationResources`
+* `-H:ReflectionConfigurationResources`
+* `-H:ResourceConfigurationResources`
+* `-H:SubstitutionResources`
By having such a composable _native-image.properties_ file, building an image
does not require any additional arguments specified on command line. It is
Documentation updated https://github.com/oracle/graal/blob/master/substratevm/BuildConfiguration.md#embedding-a-configuration-file
I'm closing the issue.
Thanks!
Most helpful comment
@olyagpl please provide the following patch to our documentation.