Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

ClientBuilder.newClient() finds no Jakarta REST client implementation

Your error

java.lang.RuntimeException: java.lang.ClassNotFoundException: Provider for jakarta.ws.rs.client.ClientBuilder cannot be found1 more line it can show

Fix it fast

Most common cause, 1 of 3

Only the API jar is present, with no client implementation

Add Jersey's client module.

Fix
<dependency>
  <groupId>org.glassfish.jersey.core</groupId>
  <artifactId>jersey-client</artifactId>
  <version>4.0.3</version>
</dependency>
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Provider for jakarta.ws.rs.client.ClientBuilder cannot be found means the Jakarta REST API jar is on the classpath but no implementation registered itself for jakarta.ws.rs. Add jersey-client 4.0.x for API 4.0 or 3.1.x for API 3.1; Jersey 2.x only serves javax. In a shaded jar, merge META-INF/services with ServicesResourceTransformer.

  • Applies to Jersey 4.0.3 and 3.1.12, jakarta.ws.rs-api 4.0.0, Spring Boot 4.2.0, maven-shade-plugin 3.6.2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print the REST API jar and every Jersey core artifact the build resolves. No Jersey line, a 2.x Jersey line, or a clean tree that still fails as a single jar each lead to a different cause.

Run this first
mvn dependency:tree -Dincludes=jakarta.ws.rs,org.glassfish.jersey.core

Then find the line you see in this list and open its fix:

  1. 1Only the API jar is present, with no client implementationThe tree lists jakarta.ws.rs:jakarta.ws.rs-api and nothing from org.glassfish.jersey.core or another REST client library
  2. 2Jersey 2.x is installed, but your code calls the jakarta.ws.rs APIThe tree shows org.glassfish.jersey.core:jersey-client 2.x next to jakarta.ws.rs-api 3.x or 4.x
  3. 3The shaded uber jar lost Jersey's META-INF/services entryThe program works from the IDE or mvn exec:java, and fails only when started as java -jar on the shaded jar

What does the error look like?

  • java.lang.RuntimeException: java.lang.ClassNotFoundException: Provider for jakarta.ws.rs.client.ClientBuilder cannot be found
  • java.lang.ClassNotFoundException: Provider for jakarta.ws.rs.client.ClientBuilder cannot be found

Cause 1 of 3

Only the API jar is present, with no client implementation

You seeThe tree lists jakarta.ws.rs:jakarta.ws.rs-api and nothing from org.glassfish.jersey.core or another REST client library

Check

The API's ClientBuilder.newBuilder() asks FactoryFinder for an implementation: first ServiceLoader entries through two class loaders, then a jaxrs.properties file under java.home, then a system property. When none of those name a class, FactoryFinder throws the Provider for jakarta.ws.rs.client.ClientBuilder cannot be found error. The API jar holds interfaces only, so a project that declares just jakarta.ws.rs-api always ends here.

Check
mvn dependency:tree -Dincludes=jakarta.ws.rs

Fix

Add Jersey's client module. A plain JDK program needs nothing more, because Jersey's client runs on HttpURLConnection by default. With the Spring Boot 4.2.0 parent you can omit the version, since Boot manages Jersey 4.0.3.

Fix
<dependency>
  <groupId>org.glassfish.jersey.core</groupId>
  <artifactId>jersey-client</artifactId>
  <version>4.0.3</version>
</dependency>

Verify

jersey-client appears in the tree, and ClientBuilder.newClient() now returns a client instead of throwing.

Verify
mvn dependency:tree -Dincludes=org.glassfish.jersey.core

Confirmed by eclipse-ee4j.github.io

Did this fix it?

Cause 2 of 3

Jersey 2.x is installed, but your code calls the jakarta.ws.rs API

You seeThe tree shows org.glassfish.jersey.core:jersey-client 2.x next to jakarta.ws.rs-api 3.x or 4.x

Check

Jersey's migration guide calls the namespace move its most fundamental change: 3.0.0 and later use jakarta, while the 2.x line stays on javax from Java EE. A Jersey 2 client therefore never answers a lookup for jakarta.ws.rs.client.ClientBuilder, even though it sits on the classpath.

Check
grep -rn "import javax.ws.rs" src/

Fix

Move every Jersey module to one jakarta-based line: 3.1.12 pairs with Jakarta REST 3.1 (Jakarta EE 10), and 4.0.3 pairs with Jakarta REST 4.0 (Jakarta EE 11, Java 17 or later). Change any remaining javax.ws.rs imports to jakarta.ws.rs.

Fix
<properties>
  <jersey.version>4.0.3</jersey.version>
</properties>
<!-- give every org.glassfish.jersey dependency ${jersey.version} -->

Verify

The tree shows a single Jersey version from the 3.1 or 4.0 line, and no source file imports javax.ws.rs.

Verify
mvn dependency:tree -Dincludes=org.glassfish.jersey.core

Confirmed by eclipse-ee4j.github.io

Did this fix it?

Cause 3 of 3

The shaded uber jar lost Jersey's META-INF/services entry

You seeThe program works from the IDE or mvn exec:java, and fails only when started as java -jar on the shaded jar

Check

Jersey announces itself through the file META-INF/services/jakarta.ws.rs.client.ClientBuilder, which names org.glassfish.jersey.client.JerseyClientBuilder. When several jars carry files under META-INF/services, the shade plugin needs a resource transformer to merge them; without one, that entry can be missing or hold another library's text in the final jar.

Check
unzip -p target/my-app.jar META-INF/services/jakarta.ws.rs.client.ClientBuilder

Fix

Add ServicesResourceTransformer to the shade execution so service files from all jars are merged into one entry each.

Fix
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.6.2</version>
  <executions>
    <execution>
      <goals><goal>shade</goal></goals>
      <configuration>
        <transformers>
          <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
        </transformers>
      </configuration>
    </execution>
  </executions>
</plugin>

Verify

The unzip command prints org.glassfish.jersey.client.JerseyClientBuilder, and java -jar runs the request.

Verify
mvn -q clean package && unzip -p target/my-app.jar META-INF/services/jakarta.ws.rs.client.ClientBuilder

Confirmed by maven.apache.org

Did this fix it?

How do I stop it coming back?

  • Declare every Jersey module through one version property, so the client, media and connector modules cannot drift onto different lines.
  • Run the packaged jar, not only the IDE build, in CI with a smoke test that creates a Client.
  • Keep ServicesResourceTransformer in every shade configuration, since any library that registers an implementation under META-INF/services needs its entry merged.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.