trying to create a keycloak object to register new user with keycloak with following code:
Keycloak keycloak = KeycloakBuilder.builder() .serverUrl(serverUrl) .realm(realm) .grantType(OAuth2Constants.PASSWORD) .clientId(clientId) .clientSecret(clientSecret) .username("someone") .password("someword") .build();
But get following error:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/jboss/resteasy/client/jaxrs/ResteasyClientBuilder] with root cause
java.lang.ClassNotFoundException: org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_131] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_131] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_131] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_131] at org.keycloak.admin.client.Keycloak.(Keycloak.java:58) ~[keycloak-admin-client-4.3.0.Final.jar:4.3.0.Final] at org.keycloak.admin.client.KeycloakBuilder.build(KeycloakBuilder.java:147) ~[keycloak-admin-client-4.3.0.Final.jar:4.3.0.Final] at hello.GreetingController.greeting(GreetingController.java:100) ~[main/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
Advertisement
Answer
Please try to add these dependencies to your project pom. Versions of dependencies could be 3.6.0.Final or 3.5.0.Final (i am not sure your keycloak-admin-client dependency version. But, i used keycloak-admin-client 3.0.0.Final with 3.5.0.Final resteasy-client. It works successfully.)
<dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-client</artifactId> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jackson2-provider</artifactId> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-multipart-provider</artifactId> </dependency>