简体   繁体   中英

Quarkus in test profile has a different working directory than in development mode, creating path problems accessing resource files

Having a file.txt inside the resources folder. And having a Bean to load that file on the Application start lifecycle:

In Development profile when compiled and running the resources folder is copied into the build (or target with maven) directory and the working dir is relative to the resources file so no need of special path or what so ever.

So basically is enough to have defined the filename in the application.properties .


In Test profile instead the working dir is the project root, so that file cannot be found anymore without giving the full relative path into the resources folder.

Is there any way to tell Quarkus test profile, and/or Microprofile config annotation, to lookup in resources folder to load some resources when needed?

I did not find anything apart a work-around to this not tidy profile difference.

I don't know if there is much we can do automatically here, gradle/maven control the working directory of the test process. With maven at least you can control the working directory of the surefire process, see this answer here: Maven: change the directory in which tests are executed

I solved by using profiled configuration, in my case seems in test the root folder is the root project folder, while in dev mode is the target folder, so I used this configuration in my property file:

cv-store-folder=./stored-cvs/
%dev.cv-store-folder=../stored-cvs/

I hope it can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM