Read file from Elasticsearch plugin


I'm trying to read a file inside my custom plugin like this:

JsonReader reader = new JsonReader(new FileReader(getClass().getClassLoader().getResource(

but I got:

access denied (\"\" \"file:/usr/share/elasticsearch/plugins/myplugin/myplugin-1.0.0.jar!/myplugin/es/plugin/file.json\" \"read\"

I tried to add:

permission "/usr/share/elasticsearch/plugins/myplugin/*", "read,write";


permission "*", "read,write";`

to my plugin-security.policy file, but same error.

Any help please?


All plugins automatically have permission to read their own jars. The problem is by trying to read this as a file directly, you have a path which is not given permission. Instead, try reading the resource as an InputStream:

JsonReader reader = new JsonReader(
    new InputStreamReader(getClass().getResourceAsStream("/myplugin/es/plugin/file.json"), StandardCharsets.UTF_8)));

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.