Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resource not found when using IntelliJ

I have a resource abc/xyz.json under src/test/resources. I'm using IntelliJ IDE. While running a Test for my project, I get the following exception.

Exception

com.google.common.io.Resources.getResource("abc/xyz.json") fails with java.lang.IllegalArgumentException: resource abc/xyz.json not found.

The Test runs fine with gradle clean build and eclipse

like image 568
sykik Avatar asked Mar 24 '17 06:03

sykik


2 Answers

Try marking your src/test/resources folder as Test Resource Root. Attach is the image on how to do it.

enter image description here

Let me know if you need any other information.

like image 62
Amit Avatar answered Sep 19 '22 23:09

Amit


Had the same issue not that long ago, since Intellij outputs the class files into out/production/{project_name}, that path will not start in the src directory but will start in the out/production/{project_name} directory.

It will however see files that are in the project root directory, I'd recommend moving your resource directory into the main project directory then accessing the file with "resources\${FILE_NAME}".

like image 22
Alec C Avatar answered Sep 21 '22 23:09

Alec C