4

I want to run the following java code:

import java.util.Map;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
import static org.elasticsearch.node.NodeBuilder.*;

public class MongoDB {

public static void main(String[] args) {
    Node node = nodeBuilder().clusterName("elasticsearch").client(true).node();
    Client client = node.client();


    node.close();
}  
}

I've run the mongod with following command:

mongod --port 27017 --replSet rs0

Elasticsearch with default conf

And everytime I run my programm I get following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/util/Version
  at org.elasticsearch.Version.<clinit>(Version.java:42)
  at org.elasticsearch.Version.<clinit>(Version.java:42)
  at org.elasticsearch.node.internal.InternalNode.<init>(InternalNode.java:129)
  at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:159)
  at org.elasticsearch.node.NodeBuilder.node(NodeBuilder.java:166)
  at org.elasticsearch.river.mongodb.MongoDB.main(MongoDB.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.Version
  at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 5 more
Java Result: 1
2
  • Elasticsearch is a search server based on Lucene . you have to include lucene jar file lucene-core-x.x.x.jar and other dependent jar files to make this code working... Commented Mar 20, 2014 at 16:36
  • Lucene dependency jars and other dependencies are available inside lib directory of elasticsearch instalation folder. You can just add that location to classpath to resolve these dependecy issues. Commented Mar 26, 2023 at 3:39

3 Answers 3

8

Elasticsearch is a search server based on Lucene . you have to include lucene jar file lucene-core-x.x.x.jar and other dependent jar files to make this code working...

Sign up to request clarification or add additional context in comments.

2 Comments

I have lucene-core jar still I am getting this exception
The Lucene Core version x.x.x needs to be > 3.0.0. We had an older Lucene (2.x) in Maven pom.xml which caused exactly the same error.
1

To use java client of elastic search.. You have 2 dependencies..
Elasticsearch jar and lucene core jar...

If you are making Osgi bundle you need to places names.txt file in bundle and specify config path in transport client settings.

Hope it helps...

Comments

0

NodeBuilder is no more in use as of latest ES (5.6.3).
Avoid using it, and start using TransportClient for future supports.

For More Info: https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_50_java_api_changes.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.