Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch exception when creating embedded node

I am trying to create an embedded node for integration tests but for some reason i am getting some exceptions while creating the node itself that some classes are missing,

I am using maven and the only import i have that related to ES is this

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>1.4.1</version>
    </dependency>

which in turn brings all of its dependencies it needs including lucene.

The exception happens in this code:

    @Bean(destroyMethod="close")
    public Client transportClient() {
        Node node = NodeBuilder.nodeBuilder().node(); //class not found
        Client client = node.client();
        return client;
    }

and the exception is as follows:

1:

java.lang.ClassNotFoundException: groovy.lang.GroovyClassLoader
at java.net.URLClassLoader$1.run(URLClassLoader.java:372) ~[na:1.8.0_25]
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_25]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_25]
at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_25]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_25]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.8.0_25]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_25]

2:

java.lang.ClassNotFoundException: org.apache.lucene.expressions.Expression
at java.net.URLClassLoader$1.run(URLClassLoader.java:372) ~[na:1.8.0_25]
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_25]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_25]
at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_25]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_25]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.8.0_25]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_25]
at org.elasticsearch.script.ScriptModule.configure(ScriptModule.java:98) ~[elasticsearch-1.4.1.jar:na]
at org.elasticsearch.common.inject.AbstractModule.configure(AbstractModule.java:60) [elasticsearch-1.4.1.jar:na]
at org.elasticsearch.common.inject.spi.Elements$RecordingBinder.install(Elements.java:204) [elasticsearch-1.4.1.jar:na]
at org.elasticsearch.common.inject.spi.Elements.getElements(Elements.java:85) [elasticsearch-1.4.1.jar:na]
like image 991
Gleeb Avatar asked Apr 16 '15 11:04

Gleeb


2 Answers

Look in the pom file of whichever version of elasticsearch you are using and find the dependencies for groovy-all and lucene-expressions. They are declared as optional dependencies and therefore you need to manually add them yo your projects pom file in order to use the elasticsearch features that use them.

For example, in the elasticserach 1.4.2 pom file I find:

<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>2.3.2</version>
    <scope>compile</scope>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>org.apache.lucene</groupId>
    <artifactId>lucene-expressions</artifactId>
    <version>4.10.2</version>
    <scope>compile</scope>
    <optional>true</optional>
</dependency>

So, because they are optional I need to add the following to my projects pom file:

<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>2.3.2</version>
</dependency>
<dependency>
    <groupId>org.apache.lucene</groupId>
    <artifactId>lucene-expressions</artifactId>
    <version>4.10.2</version>
</dependency>
like image 105
Caleb Walker Avatar answered Sep 29 '22 01:09

Caleb Walker


Was the same for me with both exceptions you've mentioned. (The only difference is the Elasticsearch version number, which is 1.3.2 in my project.)

To get rid of the exceptions, I've tried to import the specified classes by adding to following dependencies explicitly to my pom.xml :

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.3.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-expressions</artifactId>
        <version>4.10.2</version>
    </dependency>

(For Elasticsearch 1.3.1 I had to choose lucene-expressions 4.9.)

I'm sorry that I can't tell why this is necessary for now, but at least it helps.

like image 36
philburns Avatar answered Sep 29 '22 00:09

philburns