# Uncaught server error: java.lang.NoClassDefFoundError implementing a custom provider for an external mysql database

**URL:** <https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142>\
**Category:** Getting advice\
**Tags:** authentication\
**Created:** [May 16, 2023, 10:16am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142 "2023-05-16T10:16:14Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![tania](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/tania/32/9460_2.png) [@tania](https://forum.keycloak.org/u/tania)\
**Post date:** [May 16, 2023, 10:16am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/1 "2023-05-16T10:16:14Z")

</div>

Hi all,  
I am using the latest keycloak server 21.1.1 and i am implementing a custom provider for communicating with an external database.  
I have a factory for creating an DAO implementation from an external library. Inside the library is tested that the dao is successfully created. The dao implementation has injected a mysqldatasource.

I successfully find the custom provider and is successfully configured with the properties regarding the database.

I have confirmed that the datasource has been successfully created by the properties, but once i try to create the DAO via factory i get the following error “Uncaught server error: java.lang.NoClassDefFoundError:”.

I use the following dependencies:  
org.keycloak:keycloak-server-spi:21.1.1  
org.keycloak:keycloak-core:21.1.1  
org.keycloak:keycloak-model-legacy:21.1.1  
org.keycloak:keycloak-model-legacy-private:21.1.1

The issue is that the code for the external library is not included into the jar. What is the best approach to include the implementation into the jar?

---

<div class="post-metadata">

**Author:** ![weltonrodrigo](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/weltonrodrigo/32/3104_2.png) [@weltonrodrigo](https://forum.keycloak.org/u/weltonrodrigo)\
**Post date:** [May 17, 2023, 1:57pm UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/2 "2023-05-17T13:57:33Z")

</div>

you can either provide the jar dependency along with your custom code in the `providers` folder or [include dependencies inside the jar](https://stackoverflow.com/questions/1729054/including-dependencies-in-a-jar-with-maven).

---

<div class="post-metadata">

**Author:** ![tania](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/tania/32/9460_2.png) [@tania](https://forum.keycloak.org/u/tania)\
**Post date:** [May 18, 2023, 9:24am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/3 "2023-05-18T09:24:43Z")

</div>

I leave the solution i had with gradle 7.4.0 and keycloak version 21.1.1

build.gradle  
plugins {  
id(“com.github.johnrengelman.shadow”) version “7.1.2”  
}

apply plugin: ‘com.github.johnrengelman.shadow’

shadowJar {

```
dependencies {

```

// list of the dependencies needs to be included in the fat jar  
include(dependency(“com.xxxxx:$Version”))

```
}

```

}

docker file  
in the gradlew command added the shadowJar  
and copied the xxxxx-all.jar file to the binaries of the keycloak with the name xxxxx.jar in order to have the jar with the same name with the custom provider.

Thank you for your responses.

---

<div class="post-metadata">

**Author:** ![toytanik](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@toytanik](https://forum.keycloak.org/u/toytanik)\
**Post date:** [December 17, 2023, 10:34pm UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/4 "2023-12-17T22:34:39Z")

</div>

Any update here ? I am getting this error : Uncaught server error: java.lang.NoClassDefFoundError: com/messagebird/MessageBirdService.I created this file based on tania’s comment 🙂 not working. help help help, messagebird 6.1.2 and keycloak 22.0.5  
my gradle :

```auto
plugins {
    id 'java'
    id 'com.github.johnrengelman.shadow' version '7.1.2' (gradle, 7.4)
}

group 'nl.company'
version = 'DUMMY_VERSION_THAT_ALWAYS_GETS_REPLACED_BY_CI'

tasks.register('setVersionToCommitSha') {
    doLast {
        String s = buildFile.getText().replaceFirst("version = '$version'", "version = '" + inputCommitSha + "'")
        buildFile.setText(s)
    }
}

sourceCompatibility = JavaVersion.VERSION_17
repositories {
    mavenCentral()
}

configurations {
    bundleLib
}

dependencies {
    implementation "org.keycloak:keycloak-server-spi-private:${keycloak}"
    implementation "org.keycloak:keycloak-server-spi:${keycloak}"
    implementation "org.keycloak:keycloak-services:${keycloak}"
    implementation "com.messagebird:messagebird-api:${messagebird}"

    testImplementation "org.junit.jupiter:junit-jupiter-api:${junit}"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit}"

}

jar {
    from {
        configurations.bundleLib.collect { it.isDirectory() ? it : zipTree(it) }
    }
    manifest {
        attributes(
                'Dependencies': "org.keycloak.keycloak-services"
        )
    }
}

shadowJar {

    dependencies {
        include(dependency("org.keycloak:keycloak-services:$keycloak")) // keycloak 22.0.5
        include(dependency("com.messagebird:messagebird-api:${messagebird}"))// messagebird 6.1.2
        include(dependency("org.keycloak:keycloak-server-spi-private:${keycloak}"))
        include(dependency("org.keycloak:keycloak-server-spi:${keycloak}"))
        include(dependency("org.keycloak:keycloak-services:${keycloak}"))
    }
}

```

---

<div class="post-metadata">

**Author:** ![tania](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/tania/32/9460_2.png) [@tania](https://forum.keycloak.org/u/tania)\
**Post date:** [December 18, 2023, 6:19pm UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/5 "2023-12-18T18:19:27Z")

</div>

Mine it worked having only the shadowJar and in the shadowJar the dependencies of yours, not keycloak’s

---

<div class="post-metadata">

**Author:** ![jamilxt](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jamilxt/32/10025_2.png) [@jamilxt](https://forum.keycloak.org/u/jamilxt)\
**Post date:** [March 18, 2024, 1:46pm UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/6 "2024-03-18T13:46:41Z")

</div>

@tania  
Hi, can you please help me out? I’ve tried shadowJar gradle plugin approach, but no luck!

---

<div class="post-metadata">

**Author:** ![tania](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/tania/32/9460_2.png) [@tania](https://forum.keycloak.org/u/tania)\
**Post date:** [March 19, 2024, 7:14am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/7 "2024-03-19T07:14:04Z")

</div>

Yes I could @jamilxt

---

<div class="post-metadata">

**Author:** ![jamilxt](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jamilxt/32/10025_2.png) [@jamilxt](https://forum.keycloak.org/u/jamilxt)\
**Post date:** [March 19, 2024, 7:25am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/8 "2024-03-19T07:25:53Z")

</div>

Can you please share with me the gradle configuration snippet you’ve done?

---

<div class="post-metadata">

**Author:** ![jamilxt](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jamilxt/32/10025_2.png) [@jamilxt](https://forum.keycloak.org/u/jamilxt)\
**Post date:** [March 19, 2024, 7:40am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/9 "2024-03-19T07:40:48Z")

</div>

> [@tania](#):
>
> in the gradlew command added the shadowJar  
> and copied the xxxxx-all.jar file to the binaries of the keycloak with the name xxxxx.jar in order to have the jar with the same name with the custom provider.

Didn’t understand this part…can you please elaborate?

---

<div class="post-metadata">

**Author:** ![tania](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/tania/32/9460_2.png) [@tania](https://forum.keycloak.org/u/tania)\
**Post date:** [March 19, 2024, 7:55am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/10 "2024-03-19T07:55:52Z")

</div>

It would be better to share with me yours?  
Mine is sothing like  
shadowJar{  
dependencies{  
include (dependency(“name” ))  
}  
}

---

<div class="post-metadata">

**Author:** ![jamilxt](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jamilxt/32/10025_2.png) [@jamilxt](https://forum.keycloak.org/u/jamilxt)\
**Post date:** [March 19, 2024, 7:58am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/11 "2024-03-19T07:58:49Z")

</div>

Here you go. In my case, Keycloak not finding MinioClient.

```auto
plugins {
    id 'java'
    id "com.diffplug.spotless" version "5.3.0"
    id "com.github.johnrengelman.shadow" version "7.1.2"
}

apply plugin: "com.github.johnrengelman.shadow"

group 'com.example.app.keycloak'
version = '0.0.2-SNAPSHOT'

java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
    withSourcesJar()
}

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.keycloak:keycloak-server-spi:$keycloakVersion"
    implementation "org.keycloak:keycloak-server-spi-private:$keycloakVersion"
    implementation "org.keycloak:keycloak-core:$keycloakVersion"
    implementation "org.keycloak:keycloak-services:$keycloakVersion"
    implementation "org.projectlombok:lombok:$lombokVersion"
    implementation "org.slf4j:slf4j-api:$slf4j"
    implementation "io.minio:minio:$minioClient"
    annotationProcessor "org.projectlombok:lombok:$lombokVersion"
}

shadowJar {
    dependencies {
        include(dependency("io.minio:minio:$minioClient"))
    }
}

spotless.java {
    eclipse()
    removeUnusedImports()
}

test {
    useJUnitPlatform()
}

tasks.withType(JavaCompile).configureEach { task ->
    {
        task.dependsOn "spotlessApply"
    }
}

```

---

<div class="post-metadata">

**Author:** ![tania](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/tania/32/9460_2.png) [@tania](https://forum.keycloak.org/u/tania)\
**Post date:** [March 19, 2024, 7:59am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/12 "2024-03-19T07:59:08Z")

</div>

Do you want to elaborate on your case, so that I better understand?

---

<div class="post-metadata">

**Author:** ![tania](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/tania/32/9460_2.png) [@tania](https://forum.keycloak.org/u/tania)\
**Post date:** [March 19, 2024, 8:01am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/13 "2024-03-19T08:01:26Z")

</div>

What version of keycloak do you use?

---

<div class="post-metadata">

**Author:** ![jamilxt](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jamilxt/32/10025_2.png) [@jamilxt](https://forum.keycloak.org/u/jamilxt)\
**Post date:** [March 19, 2024, 8:06am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/14 "2024-03-19T08:06:27Z")

</div>

I am developing an extension for Keycloak to upload the profile picture of the user. Minio is the client I am using for storing the profile pictures.

I am using the version:  
java: 17  
gradle: 7.5.1  
keycloak: 21.0.1

---

<div class="post-metadata">

**Author:** ![tania](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/tania/32/9460_2.png) [@tania](https://forum.keycloak.org/u/tania)\
**Post date:** [March 19, 2024, 8:09am UTC](https://forum.keycloak.org/t/uncaught-server-error-java-lang-noclassdeffounderror-implementing-a-custom-provider-for-an-external-mysql-database/22142/15 "2024-03-19T08:09:05Z")

</div>

My case was about a custom provider. I have created a folder called keycloak/provider-binaries and I put my generated jar there. Whatever I have into this folder I put into /opt/keycloak/providers/  
If you dont have the correct jar into the /opt/keycloak/providers/, keycloak won’t find the right packages
