# Custom Realm Plugin install fails on jar hell error

**URL:** <https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627>\
**Category:** Elasticsearch\
**Created:** [August 1, 2018, 4:52pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627 "2018-08-01T16:52:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gautu7](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gautu7](https://discuss.elastic.co/u/gautu7)\
**Post date:** [August 1, 2018, 4:52pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/1 "2018-08-01T16:52:54Z")

</div>

I have a custom plugin on my local elastic 6.3.2 environment. After packaging this and when I try to run the install command, it was failing to recognize the SecurityExtension class on a provided maven scope, so I included all transitive dependencies as mentioned in [https://www.elastic.co/guide/en/elasticsearch/reference/6.3/setup-xpack-client.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.3/setup-xpack-client.html) after changing scope to compile.  
This introduces a whole host of jars which I don't need and x-pack is in the org.elasticsearch.xpack.\* library, do I have to exclude each one until I have only the xpack.\* libraries? or is there a dependency which will get me just that, I do not want to copy the xpack.core jar as part of my packaging from my share until that's the last resort.  
I was wondering how others are getting around this, any suggestions would help.

Error  
Caused by: java.lang.IllegalStateException: jar hell!  
class: org.elasticsearch.cli.Terminal$ConsoleTerminal  
jar1: C:\Program Files\elasticsearch-6.3.2\lib\elasticsearch-cli-6.3.2.jar  
jar2: C:\Program Files\elasticsearch-6.3.2\plugins.installing-5426440422517939048\elasticsearch-cli-6.3.2.jar  
at org.elasticsearch.bootstrap.JarHell.checkClass(JarHell.java:273)  
at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:190)  
at org.elasticsearch.plugins.PluginsService.checkBundleJarHell(PluginsService.java:609)  
... 12 more

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [August 1, 2018, 6:39pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/2 "2018-08-01T18:39:29Z")

</div>

You'll need to depend on the x-pack security jar as a provided dependency, and specify in your plugin descriptor that you are extending `x-pack-security`. Have you looked at the [example api security extension](https://github.com/elastic/elasticsearch/tree/master/x-pack/qa/security-example-spi-extension)?

---

<div class="post-metadata">

**Author:** ![gautu7](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gautu7](https://discuss.elastic.co/u/gautu7)\
**Post date:** [August 1, 2018, 6:44pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/3 "2018-08-01T18:44:05Z")

</div>

I could find x-pack-core dependency and pulling in seem to help with it.

> ```
> <dependency>
> <groupId>org.elasticsearch.plugin</groupId>
> <artifactId>x-pack-core</artifactId>
> <version>${elasticsearch.version}</version>
> </dependency>
> 
> ```

I packaged my zip with this jar as well, ran the install and the error went away. I can try pulling in x-pack-security because that's really just the one I want so that it would not get the other unneeded jars

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [August 1, 2018, 8:04pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/4 "2018-08-01T20:04:41Z")

</div>

Note that it is important those are marked as provided. Your plugin should compile against them (core and security jars), but not include them in your own plugin zip. This is because by declaring your plugin to extend x-pack-security, your plugin will be loaded in a way the classes are pulled in from x-pack core and security classes already loaded by elasticsearch. If you include these jars in your own plugin SPI could never work because the SecurityExtension interface would be a different loaded version than that in x-pack-security.

---

<div class="post-metadata">

**Author:** ![gautu7](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gautu7](https://discuss.elastic.co/u/gautu7)\
**Post date:** [August 1, 2018, 8:22pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/5 "2018-08-01T20:22:10Z")

</div>

When I started off with the java.lang.NoClassDefFoundError, the documentation ([Configuring X-Pack Java Clients | Elasticsearch Guide [6.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/6.3/setup-xpack-client.html)) said I need to add x-pack-transport to the classpath and all it's dependencies, so I had this scope as compile to pull in the jar but excluded all transitive dependencies as it was causing the jar hell error, lot of the jars which the x-pack-transport pulls are already present. To fix this, I got my own x-pack-core jar with the custom zip so that it's recognized at compile time and helped fix the error.  
Now, I tried what you said by having the x-pack-core and x-pack-security as provided and I'm back to square 1 with the same initial error -

> java.lang.NoClassDefFoundError: org/elasticsearch/xpack/core/security/SecurityExtension  
> at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?]  
> at java.lang.ClassLoader.defineClass(ClassLoader.java:1009) ~[?:?]  
> at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) ~[?:?]  
> at java.net.URLClassLoader.defineClass(URLClassLoader.java:545) ~[?:?]  
> at java.net.URLClassLoader.access$100(URLClassLoader.java:83) ~[?:?]  
> at java.net.URLClassLoader$1.run(URLClassLoader.java:453) ~[?:?]  
> at java.net.URLClassLoader$1.run(URLClassLoader.java:447) ~[?:?]  
> at java.security.AccessController.doPrivileged(Native Method) ~[?:?]  
> at java.net.URLClassLoader.findClass(URLClassLoader.java:446) ~[?:?]  
> at java.lang.ClassLoader.loadClass(ClassLoader.java:566) ~[?:?]  
> at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:890) ~[?:?]  
> at java.lang.ClassLoader.loadClass(ClassLoader.java:499) ~[?:?]  
> at org.elasticsearch.plugins.PluginsService.loadPluginClass(PluginsService.java:668) ~[elasticsearch-6.3.2.jar:6  
> .3.2]  
> at org.elasticsearch.plugins.PluginsService.loadBundle(PluginsService.java:642) ~[elasticsearch-6.3.2.jar:6.3.2]  
> at org.elasticsearch.plugins.PluginsService.loadBundles(PluginsService.java:557) ~[elasticsearch-6.3.2.jar:6.3.2  
> ]  
> at org.elasticsearch.plugins.PluginsService.(PluginsService.java:162) ~[elasticsearch-6.3.2.jar:6.3.2]  
> at org.elasticsearch.node.Node.(Node.java:311) ~[elasticsearch-6.3.2.jar:6.3.2]  
> at org.elasticsearch.node.Node.(Node.java:252) ~[elasticsearch-6.3.2.jar:6.3.2]  
> at org.elasticsearch.bootstrap.Bootstrap$5.(Bootstrap.java:213) ~[elasticsearch-6.3.2.jar:6.3.2]  
> at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.3.2.jar:6.3.2]  
> at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.3.2.jar:6.3.2]  
> at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.3.2.jar:6.3.2]  
> at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.3.2.jar:6.3.2]  
> at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.3.2.  
> jar:6.3.2]  
> at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.3.2.jar:6.3.2]  
> at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.3.2.jar:6.3.2]  
> at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.3.2.jar:6.3.2]  
> at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]  
> Caused by: java.lang.ClassNotFoundException: org.elasticsearch.xpack.core.security.SecurityExtension  
> at java.net.URLClassLoader.findClass(URLClassLoader.java:466) ~[?:?]  
> at java.lang.ClassLoader.loadClass(ClassLoader.java:566) ~[?:?]  
> at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:890) ~[?:?]  
> at java.lang.ClassLoader.loadClass(ClassLoader.java:499) ~[?:?]  
> ... 28 more

Which makes me think that elastic wants to bring in our x-pack jars with the zip and the rest of the functionalities outside x-pack are provided.

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [August 1, 2018, 8:42pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/6 "2018-08-01T20:42:22Z")

</div>

What does your plugin descriptor look like? Also, why are you bringing in the transport client? This won't work. You need to either use the NodeClient that is accessible through createComponents in your plugin, or use rest apis.

---

<div class="post-metadata">

**Author:** ![gautu7](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gautu7](https://discuss.elastic.co/u/gautu7)\
**Post date:** [August 1, 2018, 8:59pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/7 "2018-08-01T20:59:15Z")

</div>

Here is my plugin descriptor.properties and the plugin.xml which loads this

> description=custom Extension  
> version=${plugins.version}  
> name=customRealm  
> classname=${elasticsearch.plugin.classname}  
> java.version=${maven.compiler.target}  
> elasticsearch.version=${elasticsearch.version}

\<?xml version="1.0"?\> plugin dir false ${basedir}/src/main/plugin-metadata plugin-security.policy plugin-descriptor.properties true / true false 

The reason why I brought in the x-pack-transport is because I was trying a few things and found the documentation which asked to bring in the transport client with default compile scope if you look at the example. I thought creating a custom realm is just extending the SecurityExtension class - [Integrating with other authentication systems | Elastic Stack Overview [7.4] | Elastic](https://www.elastic.co/guide/en/elastic-stack-overview/current/custom-realms.html), I want to be able to implement it this way.

---

<div class="post-metadata">

**Author:** ![gautu7](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gautu7](https://discuss.elastic.co/u/gautu7)\
**Post date:** [August 1, 2018, 9:16pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/8 "2018-08-01T21:16:22Z")

</div>

Is this the one I'm missing?

'extended.plugins': other plugins this plugin extends through SPI  
As this plugin provides a SecurityExtension, it must extend x-pack-security  
extended.plugins=x-pack-security

---

<div class="post-metadata">

**Author:** ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)\
**Post date:** [August 1, 2018, 9:59pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/9 "2018-08-01T21:59:47Z")

</div>

All the info you need is spelt out in this blog post, including a sample maven build file.

> **[How to Develop Your Own Security Extensions and Custom Realms for Elasticsearch](https://www.elastic.co/blog/how-to-develop-your-own-security-extensions-and-custom-realms-for-elasticsearch)**
>
> Learn how to build and deploy your own X-Pack security extensions and custom realms for Elasticsearch 6.3

---

<div class="post-metadata">

**Author:** ![gautu7](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gautu7](https://discuss.elastic.co/u/gautu7)\
**Post date:** [August 1, 2018, 10:05pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/10 "2018-08-01T22:05:22Z")

</div>

I just happened to find this and did include the extended.plugins=x-pack-security in my descriptor and just bringing in x-pack-core with provided as @rjernst mentioned above. All the errors I had before went away but getting a unknown realm type exception

Caused by: java.lang.IllegalArgumentException: unknown realm type [myRealm] set for realm [custom]  
at org.elasticsearch.xpack.security.authc.Realms.initRealms(Realms.java:159) ~[?:?]  
at org.elasticsearch.xpack.security.authc.Realms.(Realms.java:63) ~[?:?]

Also, is it mandatory to include the META-INF folder like mentioned in the post above?  
META-INF/services/org.elasticsearch.xpack.core.security.SecurityExtension file

---

<div class="post-metadata">

**Author:** ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)\
**Post date:** [August 1, 2018, 10:54pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/11 "2018-08-01T22:54:23Z")

</div>

> [@gautu7](#):
>
> Also, is it mandatory to include the META-INF folder like mentioned in the post above?  
> META-INF/services/org.elasticsearch.xpack.core.security.SecurityExtension file

Yes, that is how you register your extension.

---

<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:** [August 29, 2018, 10:54pm UTC](https://discuss.elastic.co/t/custom-realm-plugin-install-fails-on-jar-hell-error/142627/12 "2018-08-29T22:54:29Z")

</div>

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