Search code examples
spring-bootmaven-3java-11maven-surefire-plugin

Getting NoSuchFileException after migrating to java11


I have unit test method that uses resources related to test folder in child, it works fine when i am running this project but when i run the parent it appends the parent path to my relative string value JsonFile not the current project path

    JsonFile = "src/test/resources" + "fileName";
    System.out.println(Paths.get("").toAbsolutePath());
    String input = new String(Files.readAllBytes(Paths.get(JsonFile)));

I am using openJDK11 , SureFire plugin 3.0.0-M3 and springboot 2.1.5.RELEASE. why this different behavior of
mvn clean install -Pjava11
java11 is profile exists in parent pom

I tried to override profile java11 and change the version of SureFire Plugin but it isn't useful, i don't know exactly where is the problem ? it works fine with java 8


Solution

  • Actually after a lot of search i found that Path.get is related to file system not the working directory link shows that after that i changed the mechanism for getting resource files that exists in test folder using classLoader like

    ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource(fileName).getFile()); JsonFile = file.getAbsolutePath();

    it works fine with parent and child mvn clean install -Pjava11 it isn't obvious what i added to change the mechanism of Path.get() but it wasn't changed from jdk 7