question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.NoClassDefFoundError: jakarta/json/JsonException

See original GitHub issue

Hello, I’m trying to use the elasticsearch-java client in a new kotlin spring boot 2.7.0-SNAPSHOT project. As soon as I add the import for JacksonJsonpMapper() I get the following error:

	at com.codinghumans.framework.elasticsearch.ElasticsearchClient.<init>(ElasticsearchClient.kt:21) ~[main/:na]
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[na:na]
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Constructor.call(CallerImpl.kt:41) ~[kotlin-reflect-1.6.0.jar:1.6.0-release-798(1.6.0)]
	at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:108) ~[kotlin-reflect-1.6.0.jar:1.6.0-release-798(1.6.0)]
	at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:159) ~[kotlin-reflect-1.6.0.jar:1.6.0-release-798(1.6.0)]
	at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:112) ~[kotlin-reflect-1.6.0.jar:1.6.0-release-798(1.6.0)]
	at org.springframework.beans.BeanUtils$KotlinDelegate.instantiateClass(BeanUtils.java:867) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:196) ~[spring-beans-5.3.14.jar:5.3.14]
	... 54 common frames omitted
Caused by: java.lang.ClassNotFoundException: jakarta.json.spi.JsonProvider
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
	... 66 common frames omitted```

This is my build.gradle.kts

```import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
	id("org.springframework.boot") version "2.7.0-SNAPSHOT"
	id("io.spring.dependency-management") version "1.0.11.RELEASE"
	id("org.flywaydb.flyway") version "8.2.0"
	kotlin("jvm") version "1.6.0"
	kotlin("plugin.spring") version "1.6.0"
}

group = "com.codinghumans"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
	mavenCentral()
	maven { url = uri("https://repo.spring.io/milestone") }
	maven { url = uri("https://repo.spring.io/snapshot") }
}

dependencies {
	implementation("co.elastic.clients:elasticsearch-java:7.16.2")
	implementation("com.fasterxml.jackson.core:jackson-databind:2.13.1")
	implementation("com.ibm.icu:icu4j:70.1")
	implementation("mysql:mysql-connector-java:8.0.27")
	implementation("org.flywaydb:flyway-mysql:8.3.0")

	implementation("org.springframework.boot:spring-boot-starter-web")
	implementation("org.springframework.boot:spring-boot-starter-validation")
	implementation("org.springframework.boot:spring-boot-starter-data-jpa")
	implementation("org.springframework.boot:spring-boot-starter-security")
	implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
	implementation("org.jetbrains.kotlin:kotlin-reflect")
	implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

	testImplementation("org.springframework.boot:spring-boot-starter-test")
	developmentOnly("org.springframework.boot:spring-boot-devtools")
}

tasks.withType<KotlinCompile> {
	kotlinOptions {
		freeCompilerArgs = listOf("-Xjsr305=strict")
		jvmTarget = "17"
	}
}

tasks.withType<Test> {
	useJUnitPlatform()
}

I’m quite new to java, so I’m a bit lost…Any idea what I might be doing wrong?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
marcmarcetcommented, Dec 27, 2021

Solved it by adding

implementation("jakarta.json:jakarta.json-api:2.0.1")
1reaction
swallezcommented, Mar 28, 2022

We’ve added some documentation on this issue related to Spring’s Gradle and Maven plugins https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/installation.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

JAXB/Moxy unmarshalling JSON runs into error Exception in ...
JAXB/Moxy unmarshalling JSON runs into error Exception in thread "main" java. lang. NoClassDefFoundError: jakarta/json/JsonException - Stack ...
Read more >
Getting this error java.lang.ClassNotFoundException: jakarta ...
Failed to instantiate [co.elastic.clients.Elasticsearch.ElasticsearchClient]: Factory method 'client' threw exception; nested exception is ...
Read more >
【解决异常】java.lang.NoClassDefFoundError: jakarta/json ...
解决完成之后报的找不到这个类nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/JsonProvider。
Read more >
Exception in thread "main" java.lang.NoClassDefFoundError
Your project cannot find the class org.json.JSONException. Most likely, the necessary jar file isn't in your CLASSPATH.
Read more >
Resolving JAR file and class loading errors - IBM
JsonException : org.apache.johnzon.core.JsonProviderImpl not found at ... IcmOiEmitter.run(IcmOiEmitter.java:78) at java.util.concurrent.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found