# Plugin throws java.lang.ClassNotFoundException

**URL:** https://discuss.elastic.co/t/plugin-throws-java-lang-classnotfoundexception/60356
**Category:** Elasticsearch
**Created:** [September 13, 2016, 9:13am UTC](https://discuss.elastic.co/t/plugin-throws-java-lang-classnotfoundexception/60356 "2016-09-13T09:13:17Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Alexander\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_ott/32/105905_2.png) [@Alexander\_Ott](https://discuss.elastic.co/u/Alexander_Ott)
#### Post date: [September 13, 2016, 9:13am UTC](https://discuss.elastic.co/t/plugin-throws-java-lang-classnotfoundexception/60356/1 "2016-09-13T09:13:17Z")

</div>

Hello,

i have wrote plugin for elasticsearch which use oracle.ucp libary. The libary use Thread.currentThread().getContextClassLoader() to load 'oracle.jdbc.OracleDriver' with elasticsearch 2.1, disabled securityManager and oracle libaries stored in \<ES\_HOME\>/lib directory everything works fine.

Now i want to update elasticsearch to version 2.4.0. Therefore i granted the permissions insdie a plugin-security.policy and stored the oracle libaries in the plugin directory. But now i always get an 'java.lang.ClassNotFoundException' cause the Thread.currentThread().getContextClassLoader() only contains the libaries of the \<ES\_HOME\>/lib directory and not the libaries of the plugin directory.

How can i solve this problem? If i store the oracle libaries in \<ES\_HOME\>/lib instead of the plugin directory i get problems with the granted permissions cause this permissions only for the plugin and it's libaries...

---

<div class="post-metadata">

### Author: ![Alexander\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_ott/32/105905_2.png) [@Alexander\_Ott](https://discuss.elastic.co/u/Alexander_Ott)
#### Post date: [September 13, 2016, 1:43pm UTC](https://discuss.elastic.co/t/plugin-throws-java-lang-classnotfoundexception/60356/2 "2016-09-13T13:43:17Z")

</div>

Why Thread.currentThread().getContextClassLoader() only returns entries of 'elasticsearch/lib/' directory?

Class.forName() returns entries of 'elasticsearch/lib/' and 'elasticsearch/plugins/myPlugin' directory

---

<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: [September 13, 2016, 10:08pm UTC](https://discuss.elastic.co/t/plugin-throws-java-lang-classnotfoundexception/60356/3 "2016-09-13T22:08:24Z")

</div>

Elasticsearch does not support class loading per thread context because threads are not isolated. All threads are shared by ES code and all plugin code. Plugin initialization code is isolated. So, a plugin can only see their own class path at startup time, composed of the Elasticsearch parent class path and the JARs in the plugin folder.

As a consequence, this breaks everything with class loading as intended by the JDK. There is no mechanism in Elasticsearch like in Java EE (context class loading).

In practice, you must either load `OracleDriver` class directly in your code, which is clumsy, or you must put your JDBC driver to the `ES_HOME/lib` directory, because Java JDK `ServiceLoader` infrastructure is not aware of any plugin class path.

---

<div class="post-metadata">

### Author: ![Alexander\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_ott/32/105905_2.png) [@Alexander\_Ott](https://discuss.elastic.co/u/Alexander_Ott)
#### Post date: [September 14, 2016, 6:01am UTC](https://discuss.elastic.co/t/plugin-throws-java-lang-classnotfoundexception/60356/4 "2016-09-14T06:01:09Z")

</div>

Thanks for your response. For now it only works when i put the JDBC driver to the `ES_HOME/lib` directory and start elasticsearch with `security.manager.enabled: false`.

Is it possible to grant permissions for the JDBC driver of `ES_HOME/lib` directory? Following the permission error with `security.manager.enabled: true`

```
SEVERE: Error while registering Oracle JDBC Diagnosability MBean.
java.security.AccessControlException: access denied ("javax.management.MBeanServerPermission" "createMBeanServer")
```

---

<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: [September 14, 2016, 6:54am UTC](https://discuss.elastic.co/t/plugin-throws-java-lang-classnotfoundexception/60356/5 "2016-09-14T06:54:02Z")

</div>

> [@Alexander\_Ott](#):
>
> javax.management.MBeanServerPermission

You have to add extra permissions to your security file, like this

```auto
permission javax.management.MBeanServerPermission "createMBeanServer";
permission javax.management.MBeanServerPermission "findMBeanServer";
permission javax.management.MBeanPermission "oracle.*", "*";
permission javax.management.MBeanTrustPermission "register";

```

Maybe it works, maybe not. I did not try it. Oracle driver needs lots of disabled security.

---

<div class="post-metadata">

### Author: ![Alexander\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_ott/32/105905_2.png) [@Alexander\_Ott](https://discuss.elastic.co/u/Alexander_Ott)
#### Post date: [September 14, 2016, 6:57am UTC](https://discuss.elastic.co/t/plugin-throws-java-lang-classnotfoundexception/60356/6 "2016-09-14T06:57:35Z")

</div>

Currently my plugin-security.policy looks like this:

```
grant {
  // needed to apply additional sandboxing
  permission java.security.SecurityPermission "createAccessControlContext";

  // Allow MBeanServerPermission createMBeanServer
  permission javax.management.MBeanServerPermission "createMBeanServer";

  // Allow MBeanTrustPermission register
  permission javax.management.MBeanTrustPermission "register";

  // Allow MBeanPermission registerMBean
  permission javax.management.MBeanPermission "*", "registerMBean";

  // Allow RuntimePermission getClassLoader
  permission java.lang.RuntimePermission "getClassLoader";
  permission java.lang.RuntimePermission "accessDeclaredMembers";
};

```

Is it correct to put it inside the plugin-security.policy at `ES_HOME/plugins/myPlugin`?

---

<div class="post-metadata">

### Author: ![Alexander\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_ott/32/105905_2.png) [@Alexander\_Ott](https://discuss.elastic.co/u/Alexander_Ott)
#### Post date: [September 14, 2016, 7:16am UTC](https://discuss.elastic.co/t/plugin-throws-java-lang-classnotfoundexception/60356/7 "2016-09-14T07:16:52Z")

</div>

It seems that plugin-security.policy at `ES_HOME/plugins/myPlugin` dosn't work for the JDBC driver of `ES_HOME/lib`

---

<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, 10:20pm UTC](https://discuss.elastic.co/t/plugin-throws-java-lang-classnotfoundexception/60356/8 "2017-07-05T22:20:24Z")

</div>


