0

I have a JSON file in /src/main/resources which I'm trying to read in the following way:

private List<String> readContextFromFile(String file) {

        List<String> context = new ArrayList<>();
        try {
            InputStream in = getClass().getClassLoader().getResourceAsStream(file);
            Map<String, ArrayList> input = objectMapper.readValue(in, HashMap.class);

            context = input.get("@context");
        } catch (IOException e) {
            LOGGER.error("Error reading value {}", e.getMessage());
        }
        return context;
    }

However, InputStream is null.

This is the file path that I pass: /resources/context.json

What am I doing wrong?

davidxxx
  • 125,838
  • 23
  • 214
  • 215
locus
  • 59
  • 1
  • 5

1 Answers1

1

1) /src/main/resources represents the source code, not the runtime code.
Compiled classes and processed resources ends in the target/classes folder not in the src folder.

2) About :

This is the file path that I pass: /resources/context.json

Why do you pass the resources token ? It is a Maven/Gradle directory that you will not retrieve at runtime. Only which is contained inside will be available at runtime.
What you want to pass is /context.json.

davidxxx
  • 125,838
  • 23
  • 214
  • 215