Anurag Ambuj
Anurag Ambuj

Reputation: 131

How to load custom property file located inside a folder in resources in graalvm native image?

I am migrating an existing spring boot project to spring boot native project. In my native spring boot project I have a property file alternate.properties in the location:

resources/config/prod/alternate.properties.

This file is manually being loaded using

PropertiesFileLoader altProps = new PropertiesFileLoader("alternate.properties");

Now when I build the native image and run the executable:

Caused by: java.io.FileNotFoundException: Property file 'alternate.properties' is not found in classpath
        at com.blusmart.trace.config.utils.PropertiesFileLoader.loadFromClasspath(PropertiesFileLoader.java:131) ~[na:na]
        ... 88 common frames omitted

JDK: GraalVM 22.3, JDK 17.0.7 OS: MacOS on M2 Chip (aarch64)

I tried adding those in a file named resource-config-prod.json (inside resources folder) like this:

{
  "resources": {
    "includes": [
      {"pattern": "src/main/resources/config/prod/alternate.properties", "fileEncoding": "UTF-8"}
    ]
  }
}

Tried many permutations for pattern, like

config/prod/alternate.properties
*.properties$
*.alternate.properties$
*.config/prod/alternate.properties$
src/main/resources/config/prod/alternate.properties
...
...
...

but to now avail, it just doesn't find the property file.

Build arguments in native-maven-plugin

<buildArgs>
    <arg>
        --verbose
        -J-XX:MaxRAMPercentage=80
        -J-XshowSettings:vm
        -Dspring.aot.enabled=true
        -H:TraceClassInitialization=true
        -H:+ReportExceptionStackTraces
        -H:+RunReachabilityHandlersConcurrently
        -H:Name=trace-app
        -H:DashboardDump=trace-app
        -H:+DashboardAll
        -H:IncludeResources=org/joda/time/tz/data/.*
        -H:ResourceConfigurationFiles=src/main/resources/resource-config-prod.json
        -H:Class=com.hidden.trace.TraceApplication
        --initialize-at-build-time=org.slf4j.LoggerFactory,ch.qos.logback,org.slf4j.MDC,org.slf4j.impl.StaticLoggerBinder,
        --initialize-at-run-time=io.netty,org.apache.commons.lang3.tuple.ImmutablePair
                                -Dspring.graal.remove-unused-autoconfig=true
                                -Dspring.graal.remove-yaml-support=true
    </arg>
</buildArgs>

Requesting your help with this, I am unable to find a solution that works online, and the documentation for Graal VM doesn't seem to help me. Is there anything I am missing, or is there any another way to do this ?

Upvotes: 0

Views: 653

Answers (0)

Related Questions