Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to use Elasticsearch Transport Client: dependencies not loaded to class path

I am using the following code to create a client on Elasticsearch:

Settings settings = Settings.builder()
    .put("cluster.name", "myClusterName")
    .build();
TransportClient client = new PreBuiltTransportClient(settings)
    .addTransportAddress(newInetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));

I am getting these errors:

Exception in thread "main" java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ActionPlugin
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<clinit>(PreBuiltTransportClient.java:54)
    at exadatum.com.exadatum.elastic.testSearch.main(testSearch.java:30)
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.plugins.ActionPlugin
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 14 more
like image 367
AS-Sher Avatar asked Nov 02 '16 04:11

AS-Sher


1 Answers

Update: this is now documented at

  • https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_log4j_2_logger.html
  • https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_using_another_logger.html

Make sure the client dependency has been added to the class path:

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>5.0.0-rc1</version>
</dependency>

This dependency may not be loading transitively from child dependencies.


You may also find that the main Elasticsearch and Apache Logging artifacts need to be on the class path as well:

<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>5.0.0-rc1</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.7</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.7</version>
</dependency>
like image 129
Dmitry Minkovsky Avatar answered Oct 16 '22 20:10

Dmitry Minkovsky