# NoClassDef org.apache.lucene.util.Version

**URL:** <https://discuss.elastic.co/t/noclassdef-org-apache-lucene-util-version/315787>\
**Category:** Elasticsearch\
**Created:** [October 4, 2022, 2:21pm UTC](https://discuss.elastic.co/t/noclassdef-org-apache-lucene-util-version/315787 "2022-10-04T14:21:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaron-mcgrath](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@aaron-mcgrath](https://discuss.elastic.co/u/aaron-mcgrath)\
**Post date:** [October 4, 2022, 2:21pm UTC](https://discuss.elastic.co/t/noclassdef-org-apache-lucene-util-version/315787/1 "2022-10-04T14:21:25Z")

</div>

I'm using the java client 7.17.6, with gradle to build the project;

```auto
implementation ("co.elastic.clients:elasticsearch-java:$elasticVersion")
implementation ("org.elasticsearch:elasticsearch-x-content:$elasticVersion")

```

Gradle grabs all of the required dependencies including the org.elasticsearch:elasticsearch:7.17.6.

Using the XContent component throws this stacktrace;

```auto
Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/util/Version
        at org.elasticsearch.common.xcontent.XContentElasticsearchExtension.getXContentWriters(XContentElasticsearchExtension.java:67)
        at org.elasticsearch.xcontent.XContentBuilder.<clinit>(XContentBuilder.java:114)
        at org.elasticsearch.xcontent.json.JsonXContent.contentBuilder(JsonXContent.java:38)
        at org.elasticsearch.xcontent.XContentFactory.contentBuilder(XContentFactory.java:107)
        at org.elasticsearch.xcontent.XContentFactory.jsonBuilder(XContentFactory.java:34)

```

I can see the package "org.apache.lucene.util" does indeed exist in the org.elasticsearch:elasticsearch:7.17.6 jar, but not the "Version" class.

Is there another dependency the documentation hasn't mentioned I should be including?  
Many thanks.

---

<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:** [October 4, 2022, 2:32pm UTC](https://discuss.elastic.co/t/noclassdef-org-apache-lucene-util-version/315787/2 "2022-10-04T14:32:30Z")

</div>

Welcome!

Why are you adding this line?

```auto
implementation ("org.elasticsearch:elasticsearch-x-content:$elasticVersion")

```

[Documentation](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/installation.html) says:

```auto
dependencies {
    implementation 'co.elastic.clients:elasticsearch-java:7.17.6'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
}

```

---

<div class="post-metadata">

**Author:** ![aaron-mcgrath](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@aaron-mcgrath](https://discuss.elastic.co/u/aaron-mcgrath)\
**Post date:** [October 4, 2022, 2:40pm UTC](https://discuss.elastic.co/t/noclassdef-org-apache-lucene-util-version/315787/3 "2022-10-04T14:40:12Z")

</div>

I'm transitioning from the rest client where we are using the XContent component, my easiest first step is to simply switch out the client transport from REST to Java client.

Therefore for now I still need the XContent.  
Oh and I do already have databind on the classpath.

---

<div class="post-metadata">

**Author:** ![aaron-mcgrath](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@aaron-mcgrath](https://discuss.elastic.co/u/aaron-mcgrath)\
**Post date:** [October 4, 2022, 2:48pm UTC](https://discuss.elastic.co/t/noclassdef-org-apache-lucene-util-version/315787/4 "2022-10-04T14:48:50Z")

</div>

I wonder how the org.elasticsearch:elasticsearch:7.17.6 jar compiles?

Line 67 of org.elasticsearch.common.xcontent.XContentElasticsearchExtension in that jar file;

```auto
writers.put(org.apache.lucene.util.Version.class, (b, v) -> b.value(Objects.toString(v)));

```

References a "org.apache.lucene.util.Version" class that doesn't appear to exist in the list of dependencies for that project.

-- EDIT  
Ok, so lucene-core is required for compilation which I can see in Maven, so that answers how this compiles.

Perhaps I just can't use XContent with the Java client without having to specify additional dependencies?

---

<div class="post-metadata">

**Author:** ![aaron-mcgrath](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@aaron-mcgrath](https://discuss.elastic.co/u/aaron-mcgrath)\
**Post date:** [October 4, 2022, 3:07pm UTC](https://discuss.elastic.co/t/noclassdef-org-apache-lucene-util-version/315787/5 "2022-10-04T15:07:28Z")

</div>

Including lucene-core:8.11.1 seems to have gotten me over the hump for anyone else who happens to be doing anything like this in future. Whether this is the right thing to do or not, I don't know.

```auto
implementation ("org.apache-lucene:lucene-core:8.11.1")

```

---

<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:** [October 4, 2022, 3:20pm UTC](https://discuss.elastic.co/t/noclassdef-org-apache-lucene-util-version/315787/6 "2022-10-04T15:20:03Z")

</div>

Don't use anymore elasticsearch server internal classes like XContent.

You should switch totally to the new client instead. One of the goal of the new client is to get rid of the Lucene dependencies 😉

---

<div class="post-metadata">

**Author:** ![aaron-mcgrath](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@aaron-mcgrath](https://discuss.elastic.co/u/aaron-mcgrath)\
**Post date:** [October 4, 2022, 3:22pm UTC](https://discuss.elastic.co/t/noclassdef-org-apache-lucene-util-version/315787/7 "2022-10-04T15:22:28Z")

</div>

Makes sense.

Thanks.

---

<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:** [November 1, 2022, 3:22pm UTC](https://discuss.elastic.co/t/noclassdef-org-apache-lucene-util-version/315787/8 "2022-11-01T15:22:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
