lundi 4 septembre 2017

Accessing a file in WEB-INF from a JUnit test fails when using maven

We have a file inside the WEB-INF/ folder. At runtime, this file is read and used to do stuff correctly. To test this, I want access to this very file in my JUnit test. How can I achieve this?

What I tried was using java.nio.file.Paths, coming from here

@Test
public void testAccessFile() throws Exception {
    File file = Paths.get("src/main/webapp/WEB-INF/bla/myFile.xlsx").toFile();
}

This just works fine, but only when running this test inside my IDE. Running it by mvn test makes it fail:

java.io.FileNotFoundException: src\main\webapp\WEB-INF\bla\myFile.xlsx 

So what can I do?

Note: I don't have the possibility to move the file, like inside src/main/resources. I needs to stay under WEB-INF.

Aucun commentaire:

Enregistrer un commentaire