Custom Realm Plugin install fails on jar hell error

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 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.

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(
at org.elasticsearch.bootstrap.JarHell.checkJarHell(
at org.elasticsearch.plugins.PluginsService.checkBundleJarHell(
... 12 more

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?

1 Like

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


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

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.

When I started off with the java.lang.NoClassDefFoundError, the documentation ( 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( ~[?:?]
at ~[?:?]
at ~[?:?]
at$100( ~[?:?]
at$ ~[?:?]
at$ ~[?:?]
at Method) ~[?:?]
at ~[?:?]
at java.lang.ClassLoader.loadClass( ~[?:?]
at ~[?:?]
at java.lang.ClassLoader.loadClass( ~[?:?]
at org.elasticsearch.plugins.PluginsService.loadPluginClass( ~[elasticsearch-6.3.2.jar:6
at org.elasticsearch.plugins.PluginsService.loadBundle( ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.plugins.PluginsService.loadBundles( ~[elasticsearch-6.3.2.jar:6.3.2
at org.elasticsearch.plugins.PluginsService.( ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.node.Node.( ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.node.Node.( ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Bootstrap$5.( ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Bootstrap.setup( ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Bootstrap.init( ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.init( ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute( ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute( ~[elasticsearch-6.3.2.
at org.elasticsearch.cli.Command.mainWithoutErrorHandling( ~[elasticsearch-cli-6.3.2.jar:6.3.2]
at org.elasticsearch.cli.Command.main( ~[elasticsearch-cli-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.main( ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.main( ~[elasticsearch-6.3.2.jar:6.3.2]
Caused by: java.lang.ClassNotFoundException:
at ~[?:?]
at java.lang.ClassLoader.loadClass( ~[?:?]
at ~[?:?]
at java.lang.ClassLoader.loadClass( ~[?:?]
... 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.

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.

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

description=custom Extension

<?xml version="1.0"?> plugin dir false ${basedir}/src/main/plugin-metadata plugin-security.policy 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 -, I want to be able to implement it this way.

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

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

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 ~[?:?]
at ~[?:?]

Also, is it mandatory to include the META-INF folder like mentioned in the post above?
META-INF/services/ file

Yes, that is how you register your extension.

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