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

**URL:** <https://discuss.elastic.co/t/issue-trying-to-access-meta-inf-services-in-custom-plugin/42382>\
**Category:** Elasticsearch\
**Created:** [February 22, 2016, 11:29am UTC](https://discuss.elastic.co/t/issue-trying-to-access-meta-inf-services-in-custom-plugin/42382 "2016-02-22T11:29:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guilhem\_Legal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilhem_legal/32/1843_2.png) [@Guilhem\_Legal](https://discuss.elastic.co/u/Guilhem_Legal)\
**Post date:** [February 22, 2016, 11:29am UTC](https://discuss.elastic.co/t/issue-trying-to-access-meta-inf-services-in-custom-plugin/42382/1 "2016-02-22T11:29:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [February 22, 2016, 9:17pm UTC](https://discuss.elastic.co/t/issue-trying-to-access-meta-inf-services-in-custom-plugin/42382/2 "2016-02-22T21:17:07Z")

</div>

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/](http://openjdk.java.net/projects/jigsaw/spec/sotms/)

---

<div class="post-metadata">

**Author:** ![Guilhem\_Legal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilhem_legal/32/1843_2.png) [@Guilhem\_Legal](https://discuss.elastic.co/u/Guilhem_Legal)\
**Post date:** [February 23, 2016, 3:02pm UTC](https://discuss.elastic.co/t/issue-trying-to-access-meta-inf-services-in-custom-plugin/42382/3 "2016-02-23T15:02:10Z")

</div>

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/](http://sis.apache.org/) which use a lot of ServiceLoader.

Guilhem Legal

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:14pm UTC](https://discuss.elastic.co/t/issue-trying-to-access-meta-inf-services-in-custom-plugin/42382/4 "2017-07-05T23:14:12Z")

</div>


