RESTful consumer exception

Answered

Hi,

I am fighting with this and I do not see how to solve this issue with IntelliJ. Could anyone give me a hand?

I have the following code:

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;

/**
* Created by  on 12/2/16.
*/
public class MyRSCLient {
public static void main(String[] argv) {
// Please, do not remove this line from file template, here invocation of web service will be inserted

Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8090/MyRS_war_exploded/helloworld");
String reply = target.request("text/plain").get(String.class);
System.out.println(reply);
}
}

 

and I am getting this when running it:

/usr/lib/jvm/java-8-oracle/bin/java -Didea.launcher.port=7536 -Didea.launcher.bin.path=/home/student/Applications/idea-IU-145.597.3/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfxswt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/management-agent.jar:/usr/lib/jvm/java-8-oracle/jre/lib/plugin.jar:/usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar:/usr/lib/jvm/java-8-oracle/javafx-src.zip:/home/student/glassfish4/glassfish/lib/javaee.jar:/home/student/student_apps/IntelliJ/untitled/out/production/MyRSConsumer:/home/student/Applications/idea-IU-145.597.3/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain MyRSCLient
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:103)
at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
at MyRSCLient.main(MyRSCLient.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:115)
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:225)
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
... 7 more

Process finished with exit code 1

 

Thanks a lot in advance.

0
3 comments

A jar with org.glassfish.jersey.client.JerseyClientBuilder class is missing from the module dependencies (http://www.jetbrains.com/idea/webhelp/configuring-module-dependencies-and-libraries.html).

0
Avatar
Permanently deleted user

Hi Serge,

  I am facing similar issue. I can see this jar is available in module dependency path. PFA the screenshot. Can you please help.

0

Try to delete .idea directory and reimport from pom.xml, if the issue persists, share a sample project with the steps to reproduce.

0

Please sign in to leave a comment.