0

In my multi module maven project ,learning_jaxrs (parent project)

enter image description here

commonapi module(packaging jar) contains resources in src/main/resources ,and i am reading files using my below util class

public class FileUtils {

private static final ClassLoader CLASS_LOADER = FileUtils.class.getClassLoader();

/**
 * @param fileName
 * @return
 * @throws IOException
 */
public static String readFileAsString(String fileName) throws IOException {
    String result = null;
    result = new String(readAllBytes(getFilePath(fileName)),StandardCharsets.UTF_8);
    return result;
}

/**
 * It will return fully qualified path of resource file name
 *
 * @param fileName
 * @return
 */
public static Path getFilePath(String fileName) {
    Path result = null;
    URL resource = CLASS_LOADER.getResource(fileName);
    if (resource != null) {
        result = get(resource.getFile());
    }
    return result;
}

}

reading file

 String jsonTestData = readFileAsString("testEmployees.json");

when i ran local tests for commonapi module everything works fine .

But its not working when i deployed httpmethods module(war) on my server ,i am getting following exception ..

java.nio.file.NoSuchFileException: /content/httpmethods-1.0.war/WEB-INF/lib/commonapi-1.0.jar/testEmployees.json

httpmethods war archive does contain commonapi jar in web-inf/lib and common api jar has file too

enter image description here enter image description here

Edit :

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

solved the problem

invariant
  • 8,758
  • 9
  • 47
  • 61

0 Answers0