I have the application packed in Graal native image.
I'm loading the properties using:
InputStream resourceAsStream = MainApplication.class.getResourceAsStream("/application.properties");
However, when I try to execute the binary, I'm getting the following error:
Exception in thread "main" java.lang.NullPointerException: inStream parameter is null
Turns out that Graal is not attaching my application.properties
file when the project is packed into native image.
I'm using Gradle and com.palantir.graal
with the following settings:
graal {
mainClass '<path-to-main-class>'
outputName '<output-name>'
javaVersion '11'
}
Is there a way I can use application.properties
from build/resources
?
For resources to be included into the native image executable they need to be configured. Static analysis cannot include them automatically.
The configuration for the resources is described in the docs.
In short it's a json file describing the resources to be included, for example:
Probably the best way to create configuration like this is to run your application on the JVM with a javaagent that would trace all things needed to be configured and output the configuration that you can include into the native image build process.
The assisted configuraion javaagent is described in the docs, but in a nutshell you run your application like:
And then use the app to execute to code paths which the agent will trace. The agent doesn't statically analyze the application, so it needs to be used to provide meaningful config.