Simply put I need to read a schema.json file for org.everit.json.schema
. In Eclipse I naively for testing I did it like this:
new String(Files.readAllBytes(Paths.get("./src/main/resources/schemas/Schema.json"))));
However when compiling and deploying to Payara I am getting a java exception file not found.
Where is or what is the best way to reference a file on the server in code (cannot seem to find a documented approach for this).
The path where Schema.json is located indicates a Maven project hierarchy. As such, the src/main/resources
folder is in the classpath. The best way to get the contents of this file from a non-static method is:
InputStream is = getClass().getResourceAsStream("/schemas/Schema.json");
And read the InputStream
.
2 notes:
ClassLoader.getResourceAsStream()