I know I can load a file from src/test/resources with:
getClass().getResource(\"somefile\").getFile()
But how can I get the full path to th
All content in src/test/resources is copied into target/test-classes folder. So to get file from test resources during maven build you have to load it from test-classes folder, like that:
Paths.get(
getClass().getProtectionDomain().getCodeSource().getLocation().toURI()
).resolve(
Paths.get("somefile")
).toFile()
Break down:
getClass().getProtectionDomain().getCodeSource().getLocation().toURI() - give you URI to target/test-classes.resolve(Paths.get("somefile")) - resolves someFile to target/test-classes folder.Original anwser is taken from this