resource not found when using IntelliJ
Asked Answered
D

5

9

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

Denby answered 24/3, 2017 at 6:43 Comment(2)
Please share the Minimal, Complete, and Verifiable example to get help.Pompano
How did you solved your problem with a resource availability?Rodriguez
A
3

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.

Antalya answered 24/3, 2017 at 8:0 Comment(2)
thats strange. can you share your complete piece of code ?Antalya
@skyik did you get the answer of your question?Antalya
B
2

Make your resource folder a Test Resource folder, if this does not fix the issue then, close your project, delete target folder and open the project. Hope this helps.

Bourgeois answered 24/1, 2020 at 22:17 Comment(0)
R
1

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}".

Recognizee answered 24/3, 2017 at 6:48 Comment(1)
I don't think manually copying files to that folder is how intelliJ creators imagined itDenby
T
1

Sometimes I have the same problem, though the folder is marked as resource root. So what I do: I just Unmark it and then mark it as resource root again. Sometimes I need to do it several times and it works. But anyway I think it is Intellij IDEA bug.

Tamelatameless answered 6/12, 2018 at 16:3 Comment(0)
I
0

For me, a "Rebuild Project" solves the issue most of the times.

Illegitimacy answered 4/6 at 6:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.