TransportClient in 2.1.x

How to create a TranspotClient in 2.1.x?

I recently updated to elastic search 2.1.x.

Iam suffering to create a TransportClient via the JAVA API.

My Code looks like

** Settings settings = Settings.settingsBuilder()**
** .put("cluster.name", "tst-found2day").build();**
** Client client = TransportClient.builder().settings(settings).build().addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("localhost", 9300)));**

When i run this, i got the following error:

java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;

** at org.elasticsearch.threadpool.ThreadPool.(ThreadPool.java:190)**
** at org.elasticsearch.client.transport.TransportClient$Builder.build(TransportClient.java:130)**

What am i doing wrong ?

Thanks,

Luuk

What Google Guava version is in your classpath?

Guava version 18.0

Luuk

I am using Gradle to build the project.

I have installed kibana and the sense plugin.
In can index via Sense, but unable to connect via java client.

Luuk

Please recheck. You have an older version of Guava in your project and this is causing the runtime error.

How do you mean?

Is version 18.0 old ?

No, version 18 is correct.

Check your classpath at runtime, your program fails because your Guava is older than version 18.

I found the following entry on my classpath

.sdkman/grails/2.5.0/lib/com.google.guava/guava/jars/guava-10.0.1.jar

before entry :

Users/luukdaemen/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar

This is probably causing it.

How can i exclude the old library from the class path, related to the build.groovy ?

If Grails could use Guava 18, then it would work. But it can't. This is more a less a Grails question.

Read the docs how to shade jars

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

Well, i managed to exclude the Guava 10.0.1.jar from my class path.

First by renaming the file directly in the sdkman folder.
This was just to show that the right jar was pcked up.
It worked.

i renamed the file back to .jar afterwards, because it is not a prober solution.

Secondly, within Intellj, i was able to remove the 10.0.1 jar from the External Libraries section within the project structure.

This causes that the 10.0.1 jar will be excluded from the class path.

Building the war file within Intellj, also excludes this jar.

So far,

Luuk