Issue trying to access META-INF/services in custom plugin

Hi everyone,

I'm currently developing a custom plugin for elasticSearch 2.2.0. One of my jar packaged in my plugin contain a file in META-INF/services and it seems to be blocked or ignored as when i call :

ServiceLoader.load(type) , it return an empty iterable object.

Is there a permission i have to add in my plugin-security.policy ?

Guilhem Legal

JDK's ServiceLoader relies on a single class loader that can access all jars in all locations globally.

ES 2.2+ has separated the class loaders for ES libs and for plugin libs. That means, you can no longer use ServiceLoader for resources in your plugin, because ES starts with a classpath that does not include plugin jars' META-INF/services entries.

You have two options:

  • switch to an alternative resource loader implementation
  • move jars that depend on ServiceLoader to $ES_HOME/lib. This location is the only location accessible by the ES class loader at node startup

Note, with the advent of JDK 9, everything related to ServiceLoader will be revamped into so-called modules. It is not clear when this happens, how deep the impact is and how fast ES will be compatible to JDK 9 modularized features, but I am confident that ES plugins will be turned into such modules in the future. See also http://openjdk.java.net/projects/jigsaw/spec/sotms/

Thank's you for your quick answer.

I moved the jar to $ES_HOME/lib (one thing leading to another, half of my libraries ended in it).
I also have to add a new policy file for the libraries i just moved and call it in Elasticsearch executable since my plugin policies are not applied to general ClassLoader:

export JAVA_OPTS="$JAVA_OPTS -Djava.security.policy=es.policy"

I finally succeed to execute all the operations on my plugin.

Anyway, I'm not very happy with the result and i think i will go back to ElasticSearch 2.0.0 (if there is no separated classloader).

Note, what i try to embed in my plugin is an Apache Library : http://sis.apache.org/ which use a lot of ServiceLoader.

Guilhem Legal

1 Like