I get this error after running a native image, the file kc.properties exists into a custom library at the src/main/resources package, and the library is used in project through .jar dependency.

Image builded with the command mvn -Pnative native:compile -Dmaven.test.skip=true.

Spring Boot 3.0.2 Java 17

java.io.UncheckedIOException: java.io.FileNotFoundException: class path resource [kc.properties] cannot be opened because it does not exist
    at controladoria.simulador.custos.calculation.SimuladorCustosCalculationApplication__ApplicationContextInitializer.processPropertySources(SimuladorCustosCalculationApplication__ApplicationContextInitializer.java:47)
    at controladoria.simulador.custos.calculation.SimuladorCustosCalculationApplication__ApplicationContextInitializer.initialize(SimuladorCustosCalculationApplication__ApplicationContextInitializer.java:31)
    at controladoria.simulador.custos.calculation.SimuladorCustosCalculationApplication__ApplicationContextInitializer.initialize(SimuladorCustosCalculationApplication__ApplicationContextInitializer.java:25)
    at org.springframework.context.aot.AotApplicationContextInitializer.initialize(AotApplicationContextInitializer.java:72)
    at org.springframework.context.aot.AotApplicationContextInitializer.lambda$forInitializerClasses$0(AotApplicationContextInitializer.java:61)
    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:603)
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:383)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291)
    at controladoria.simulador.custos.calculation.SimuladorCustosCalculationApplication.main(SimuladorCustosCalculationApplication.java:29)
Caused by: java.io.FileNotFoundException: class path resource [kc.properties] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:211)
    at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:159)
    at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:100)
    at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:74)
    at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:60)
    at org.springframework.core.io.support.ResourcePropertySource.<init>(ResourcePropertySource.java:67)
    at org.springframework.core.io.support.DefaultPropertySourceFactory.createPropertySource(DefaultPropertySourceFactory.java:37)
    at org.springframework.core.io.support.PropertySourceProcessor.processPropertySource(PropertySourceProcessor.java:87)
    at controladoria.simulador.custos.calculation.SimuladorCustosCalculationApplication__ApplicationContextInitializer.processPropertySources(SimuladorCustosCalculationApplication__ApplicationContextInitializer.java:45)
    ... 10 common frames omitted

Comment From: diegohenriquef

I tried to use the resource-config.json mentioned in GraalVM with -H:ResourceConfigurationFiles=${basedir}/resource-config.json in native-maven-plugin in pom.xml, but it did not work.

I tried too use -H:IncludeResources="./kc.properties$" in native-maven-plugin in pom.xml, but it didn't work either.

resource-config.json

{
    "bundles": [
        {
            "name": "luizalabs.gestaocorp.controladoria-commons"
        },
        {
            "name": "luizalabs.gestaocorp.controladoria-security"
        },
        {
            "name": "luizalabs.gestaocorp.controladoria-simulador-custos-entity"
        }
    ],
    "resources": {
        "includes": [
            {
                "pattern": "controladoria-security:.*/kc.*properties$"
            },
            {
                "pattern": ".*/application.*yml$"
            },
            {
                "pattern": ".*/logback.*xml$"
            }
        ]
    }
}

Comment From: wilkinsona

The pattern appears to be incorrect. If the file is in src/main/resources it will be in the root of the classpath. Therefore, the pattern could simply be kc.properties. You can use -H:Log=registerResource to configure Graal to log every included resource at build time. This should help you to configure the correct pattern. I'm going to close this now as this is out of Spring Boot's control. If you can see that Graal is including the resource in the image and it still cannot be loaded at runtime, please provide a minimal sample that reproduces that behavior and we can re-open this issue and take a look.

Comment From: mhalbritter

You can also use the RuntimeHintsRegistrar API (see here) if you don't want to fiddle around with JSON.