# Version 5 and Java not working

**URL:** <https://discuss.elastic.co/t/version-5-and-java-not-working/64589>\
**Category:** Elasticsearch\
**Created:** [November 1, 2016, 4:55pm UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589 "2016-11-01T16:55:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Davis](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@Andrew\_Davis](https://discuss.elastic.co/u/Andrew_Davis)\
**Post date:** [November 1, 2016, 4:55pm UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/1 "2016-11-01T16:55:35Z")

</div>

Ok, i am looking at using ElasticSearch, via Java, for one of my applications,  
and have installed version 5.0.0 and have it running ok, in about 10 mins  
i have now copied, the Jar file down, into my test app, (netbeans is my development environment 8.0.2) , using start Jar file elasticsearch-5.0.0.jar no marven  
and using the example from the docs/web page

public static void main(String[] args)  
{

```
    TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(""), 9300));
    client.close();
}

```

and i am getting a comple error on PreBuiltTransportClient, and it does not apper to be in the Jar files, or am i missing some thing.  
or is there another example else where, that does not use "PreBuiltTransportClient"

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 1, 2016, 5:07pm UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/2 "2016-11-01T17:07:52Z")

</div>

This class belongs to the Transport jar. See [https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/\_maven\_repository.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_maven_repository.html)

---

<div class="post-metadata">

**Author:** ![geoffhowe1961](https://avatars.discourse-cdn.com/v4/letter/g/85f322/32.png) [@geoffhowe1961](https://discuss.elastic.co/u/geoffhowe1961)\
**Post date:** [November 30, 2016, 2:48am UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/3 "2016-11-30T02:48:17Z")

</div>

Ok so I'm having the same problem. I've added the transport library through the pom entry shown, but the reference to Settings.EMPTY is complaining that it can't be resolved. Next idea?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 30, 2016, 9:41am UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/4 "2016-11-30T09:41:02Z")

</div>

May be refresh your IDE or run `mvn clean install`?  
What is the exact error?

---

<div class="post-metadata">

**Author:** ![geoffhowe1961](https://avatars.discourse-cdn.com/v4/letter/g/85f322/32.png) [@geoffhowe1961](https://discuss.elastic.co/u/geoffhowe1961)\
**Post date:** [November 30, 2016, 2:41pm UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/5 "2016-11-30T14:41:00Z")

</div>

I'm using Eclipse, and have refreshed the project, forced clean several times. The portion of text of the example with the problem is:

TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)

The word EMPTY is highlighted and when I hover over it this is the exact message:

"EMPTY cannot be resolved or is not a field"

This is generally the message when the object definition doesn't exist in the project.  
However, if I purposefully change the reference to something else, such as "EMPTYS", in addition to getting the same message (e.g., "... cannot be resolved or is not a field") it does prompt me to change it to "EMPTY\_PARAMS". When I do that, however, then the error changes to highlight the entire constructor statement:

new PreBuiltTransportClient(Settings.EMPTY\_PARAMS)

and says "The constructor PreBuiltTransportClient(ToXContent.Params) is undefined"

My imports in this class include:  
import org.elasticsearch.common.settings.Settings;  
import org.elasticsearch.common.transport.InetSocketTransportAddress;  
import org.elasticsearch.transport.client.PreBuiltTransportClient;

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 30, 2016, 3:14pm UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/6 "2016-11-30T15:14:01Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

I just checked on my end and as soon as I add the following in my `pom.xml` file:

```auto
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>5.0.2</version>
</dependency>

```

I can write this code:

```auto
new PreBuiltTransportClient(Settings.EMPTY)
      .addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));

```

If it does not work on your end, then check your IDE, your maven settings, look at eclipse messages.

What does `mvn dependency:tree` is saying?

---

<div class="post-metadata">

**Author:** ![geoffhowe1961](https://avatars.discourse-cdn.com/v4/letter/g/85f322/32.png) [@geoffhowe1961](https://discuss.elastic.co/u/geoffhowe1961)\
**Post date:** [December 2, 2016, 9:43pm UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/7 "2016-12-02T21:43:49Z")

</div>

I changed the version to 5.0.2 (although just last night the example gave me 5.0.1 as the version to use - fyi). Same problem. Then as I was trying to create a settings object directly, I discovered that there was some weird conflict between your code and the version of SpringBoot I had been trying to use (1.3.5). I upgraded to 1.4.2 and made a few other adjustments (had an unrelated LOGGER issue with the change) and now your code compiles and I can run the demonstration. Thanks for the hint...

---

<div class="post-metadata">

**Author:** ![geoffhowe1961](https://avatars.discourse-cdn.com/v4/letter/g/85f322/32.png) [@geoffhowe1961](https://discuss.elastic.co/u/geoffhowe1961)\
**Post date:** [December 2, 2016, 10:15pm UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/8 "2016-12-02T22:15:06Z")

</div>

I spoke too soon. While I compiled correctly, I'm getting a run time error now about

```
Exception in thread "main" java.lang.NoSuchMethodError: org.elasticsearch.client.transport.TransportClient.<init>(Lorg/elasticsearch/common/settings/Settings;Lorg/elasticsearch/common/settings/Settings;Ljava/util/Collection;Lorg/elasticsearch/client/transport/TransportClient$HostFailureListener;)V
	at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:92)
	at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:81)
	at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:71)
	at com.eab.certified.App.testPutAndGet(App.java:94)
	at com.eab.certified.App.main(App.java:58)

```

This is happening right at the same line of code:

```
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
 .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200));
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 4, 2016, 6:20am UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/9 "2016-12-04T06:20:51Z")

</div>

You are missing dependencies or you imported wrong dependencies or you are mixing multiple versions.

---

<div class="post-metadata">

**Author:** ![geoffhowe1961](https://avatars.discourse-cdn.com/v4/letter/g/85f322/32.png) [@geoffhowe1961](https://discuss.elastic.co/u/geoffhowe1961)\
**Post date:** [December 5, 2016, 12:39am UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/10 "2016-12-05T00:39:44Z")

</div>

Ok, now I think I have it. I might suggest that the demo example include a bit more details. I had stitched together things from several different places, and what finally worked was having the following settings in my pom. I'm in business finally!

```
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.7</java.version>
		<elasticsearch.version>5.0.2</elasticsearch.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-to-slf4j</artifactId>
			<version>2.6.2</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.21</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-simple</artifactId>
			<version>1.7.21</version>
		</dependency>
		<!-- Elastic Search REST CLient -->
		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>rest</artifactId>
			<version>5.0.2</version>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>transport</artifactId>
			<version>5.0.2</version>
		</dependency>
	</dependencies>
```

---

<div class="post-metadata">

**Author:** ![rMethre](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@rMethre](https://discuss.elastic.co/u/rMethre)\
**Post date:** [April 12, 2017, 11:49am UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/11 "2017-04-12T11:49:34Z")

</div>

I am getting below error can you pls here, Elastic search jar Version used 5.1.1

SEVERE: Servlet.service() for servlet [issuetracker] in context with path [/issuetracker] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.elasticsearch.transport.client.PreBuiltTransportClient.addPlugins(Ljava/util/Collection;Ljava/util/Collection;)Ljava/util/Collection;] with root cause  
java.lang.NoSuchMethodError: org.elasticsearch.transport.client.PreBuiltTransportClient.addPlugins(Ljava/util/Collection;Ljava/util/Collection;)Ljava/util/Collection;  
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:92)  
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:81)  
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:71)

---

<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:01pm UTC](https://discuss.elastic.co/t/version-5-and-java-not-working/64589/12 "2017-07-05T22:01:15Z")

</div>


