oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.44k stars 1.64k forks source link

In native image load resources from filesystem like usual java does #7882

Open nevinitsin opened 1 year ago

nevinitsin commented 1 year ago

Feature request

I am stuck with cassandra. It loads configuration files like this (I can't change its code):

getClass().getClassLoader().getResource("cassandra.yaml")
getClass().getClassLoader().getResourceAsStream("cassandra.topology")

But before that, my application writes these files to a directory, which is on classpath. The files are different for different cassandra clusters, so they cannot be compiled into native image.

In jvm it works, cassandra reads just-written config files and starts. In native image it only throws error message "Cannot locate cassandra.yaml".

Describe the solution you'd like. I want native image to be able to load resources from filesystem, and to be configurable at runtime: in which directories to look up resources.

Describe who do you think will benefit the most. Everyone who use libraries which read files as resources

Describe alternatives you've considered. As for cassandra: cassandra.yaml part can be worked around by specifying -Dcassandra.config=path (and cassandra it self is working), but unfortunately cassandra.topology and commitlog-archiving are hard-coded and must be loaded as regular file on classpath, that's why it is impossible to setup even development cluster at the moment.

But in general, I see no alternatives.

hamzaGhaissi commented 1 year ago

Thanks for the future request

olpaw commented 10 months ago

I am stuck with cassandra. It loads configuration files like this (I can't change its code):

getClass().getClassLoader().getResource("cassandra.yaml")
getClass().getClassLoader().getResourceAsStream("cassandra.topology")

But before that, my application writes these files to a directory, which is on classpath. The files are different for different cassandra clusters, so they cannot be compiled into native image.

As you correctly pointed out, this is something that we currently do not support in native-image. Java projects that assume that they can rely on always being loaded from a directory-based class-path entry and therefore file access in their sources when they read from that directory can be expressed as Java resource access will not work when built into a native image.