user3239600
user3239600

Reputation: 321

Is there any way to read main application resources from quarkus extension code?

What i have

  1. @ApplicationScoped class with onStart method that is trying to read resource file with getClass().getClassLoader().getResourceAsStream() method;

  2. @BuildStep with AdditionalBeanBuildItem that produces my @ApplicatinScoped class.

What i want to do

Get access to resource folder of application that uses my quarkus extension and read a file.

What is my problem

My quarkus extension can't seems to acces it (it read its own resources instead).

I guess i just need to use a different producer but i'm not sure which one.

Upvotes: 0

Views: 2953

Answers (1)

geoand
geoand

Reputation: 63991

For one, you should be using Thread.currentThread().getContextClassLoader() as the ClassLoader.

Other than that, Quarkus provides a few utilities like ClasspathUtils and FileUtil that will be useful.

A great example of how all this comes together is code that allows a user to customize the banner.

See https://github.com/quarkusio/quarkus/blob/2.3.0.Final/core/deployment/src/main/java/io/quarkus/deployment/steps/BannerProcessor.java#L46 for all the details

Upvotes: 5

Related Questions