Skip to content

Commit 8875ef2

Browse files
Refactor docs for JsonProvider error (#265) (#266)
Co-authored-by: Sylvain Wallez <[email protected]>
1 parent 8d18ca4 commit 8875ef2

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

docs/getting-started/installation.asciidoc

+34-16
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,8 @@ available at https://snapshots.elastic.co/maven/.
2626
dependencies {
2727
implementation 'co.elastic.clients:elasticsearch-java:{version}'
2828
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
29-
30-
// Needed only if you use the spring-dependency-management
31-
// and spring-boot Gradle plugins
32-
implementation 'jakarta.json:jakarta.json-api:2.0.1' //<1>
3329
}
3430
--------------------------------------------------
35-
<1> See <<spring-jakarta-json>> for additional details.
3631

3732
[discrete]
3833
[[maven]]
@@ -58,8 +53,35 @@ dependencies:
5853
<version>2.12.3</version>
5954
</dependency>
6055
61-
<!-- Needed only if you use the spring-boot Maven plugin -->
62-
<dependency> <!--1-->
56+
</dependencies>
57+
</project>
58+
--------------------------------------------------
59+
60+
61+
[discrete]
62+
[[class-not-found-jsonprovider]]
63+
==== If you get ClassNotFoundException: jakarta.json.spi.JsonProvider
64+
65+
It may happen that after setting up the dependencies, your application fails with `ClassNotFoundException: jakarta.json.spi.JsonProvider`.
66+
67+
If this happens, you have to explicitly add the `jakarta.json:jakarta.json-api:2.0.1` dependency.
68+
69+
.Gradle:
70+
["source","groovy",subs="attributes+"]
71+
--------------------------------------------------
72+
dependencies {
73+
...
74+
implementation 'jakarta.json:jakarta.json-api:2.0.1'
75+
}
76+
--------------------------------------------------
77+
78+
.Maven:
79+
["source","xml",subs="attributes+"]
80+
--------------------------------------------------
81+
<project>
82+
<dependencies>
83+
...
84+
<dependency>
6385
<groupId>jakarta.json</groupId>
6486
<artifactId>jakarta.json-api</artifactId>
6587
<version>2.0.1</version>
@@ -68,19 +90,15 @@ dependencies:
6890
</dependencies>
6991
</project>
7092
--------------------------------------------------
71-
<1> See <<spring-jakarta-json>> for additional details.
7293

94+
**Why is this needed?**
7395

74-
[discrete]
75-
[[spring-jakarta-json]]
76-
==== Spring Boot and jakarta.json
77-
78-
Spring Boot comes with Gradle and Maven plugins to ease development and dependency management. These plugins define built-in versions for a number of well-known libraries.
96+
Some frameworks like Spring Boot or Helidon come with their Gradle and Maven plugins or their Maven BOM files to ease development and dependency management. These plugins and BOM define the versions to use for a number of well-known libraries.
7997

80-
One these libraries is `jakarta.json:json-api` that defines the standard Java JSON API. In version `1.x` this library used the `javax.json` package, while in version `2.x` it uses the `jakarta.json` package after https://blogs.oracle.com/javamagazine/post/transition-from-java-ee-to-jakarta-ee[the transition from JavaEE to JakartaEE].
98+
One these libraries can be `jakarta.json:json-api` that defines the standard Java JSON API. In version `1.x` this library used the `javax.json` package, while in version `2.x` it uses the `jakarta.json` package after https://blogs.oracle.com/javamagazine/post/transition-from-java-ee-to-jakarta-ee[the transition from JavaEE to JakartaEE].
8199

82-
The {java-client} depends on version `2.0.1` of this library, in order to use the newer and future-proof `jakarta.json` package. But Spring Boot's Gradle plugin (at least in version `2.6` and below) overrides the {java-client}'s dependency to use version `1.1.6` in the older `javax.json` namespace.
100+
The {java-client} depends on version `2.0.1` of this library, in order to use the newer and future-proof `jakarta.json` package. But some build plugins and BOMs override the {java-client}'s dependency to use version `1.x` in the older `javax.json` namespace, resulting in `ClassNotFoundException: jakarta.json.spi.JsonProvider`.
83101

84-
This is why you have to explicitly add the `jakarta.json:jakarta.json-api:2.0.1` dependency. Otherwise, this will result in the following exception at runtime: `java.lang.ClassNotFoundException: jakarta.json.spi.JsonProvider`.
102+
Adding the correct version as top-level project dependency solves the problem.
85103

86104
If your application also requires `javax.json` you can add the `javax.json:javax.json-api:1.1.4` dependency, which is equivalent to `jakarta.json:jakarta.json-api:1.1.6`.

0 commit comments

Comments
 (0)